Skip to content

Instantly share code, notes, and snippets.

package examples
import (
"context"
"fmt"
"log"
"net/http"
"os"
"strconv"
"time"
package site
import (
"fmt"
"github.com/dustin/go-humanize"
build "github.com/starfederation/datastar/build"
datastar "github.com/starfederation/datastar/sdk/go"
)
templ Home() {
router.Route("/api", func(apiRouter chi.Router) {
apiRouter.Route("/todos", func(todosRouter chi.Router) {
todosRouter.Get("/", func(w http.ResponseWriter, r *http.Request) {
sessionID, mvc, err := mvcSession(w, r)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
package examples
import (
"context"
"fmt"
"log"
"net/http"
"os"
"strconv"
"time"
<div
id="demo"
data-signals="{ values: { 0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0 } }"
data-computed:bar="Object.values($values).join('')"
data-on-signal-patch="@post('/examples/one_time_passcode')"
>
<h3>OTP Input:</h3>
<div
data-on:keydown__prevent="
const input = event.target;
class OtpInput extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: "open" });
this.values = [];
}
connectedCallback() {
this.length = Number(this.getAttribute("length") || 6);
this.values = Array(this.length).fill("");
package examples
import (
"context"
"fmt"
"log"
"net/http"
"os"
"strconv"
"time"
package examples
import (
"github.com/go-chi/chi/v5"
"github.com/starfederation/datastar-dev/site/auth"
. "github.com/starfederation/datastar-dev/site/shared"
"github.com/starfederation/datastar-go/datastar"
"net/http"
"regexp"
)