package handler import ( "fmt" "github.com/imkira/go-observer" "net/http" "strconv" ) type Value struct { VersionRef int } func SyncFactory(obs observer.Property) HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { versionRef, err := strconv.Atoi(r.URL.Query().Get("v")) if err != nil { versionRef = -1 } stream := obs.Observe() var value Value for { value = stream.Value().(Value) if value.VersionRef >= versionRef { break } select { case <-stream.Changes(): stream.Next() } } w.Header().Add("Content-Type", "text/plain") fmt.Fprintf(w, "%d (%d)\n", value.VersionRef, versionRef) } }