refactoring

This commit is contained in:
Settel 2021-07-30 21:49:18 +02:00
parent 56cd5b4698
commit caa1c06ccf
3 changed files with 11 additions and 8 deletions

View File

@ -4,6 +4,7 @@ import (
"fmt"
"github.com/imkira/go-observer"
"sirlab.de/go/knyt/handler"
"sirlab.de/go/knyt/syncdata"
"time"
)
@ -13,14 +14,14 @@ type Engine struct {
func NewEngine() *Engine {
engine := Engine{
obs: observer.NewProperty(handler.Value{}),
obs: observer.NewProperty(syncdata.SyncData{}),
}
return &engine
}
func (engine *Engine) Run() {
for {
value := engine.obs.Value().(handler.Value)
value := engine.obs.Value().(syncdata.SyncData)
fmt.Printf("sleep: %d\n", value.VersionRef)
time.Sleep(1 * time.Second)
value.VersionRef++

View File

@ -5,13 +5,10 @@ import (
"fmt"
"github.com/imkira/go-observer"
"net/http"
"sirlab.de/go/knyt/syncdata"
"strconv"
)
type Value struct {
VersionRef int `json:"version"`
}
func SyncFactory(obs observer.Property) HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
versionRef, err := strconv.Atoi(r.URL.Query().Get("v"))
@ -20,9 +17,9 @@ func SyncFactory(obs observer.Property) HandlerFunc {
}
stream := obs.Observe()
var value Value
var value syncdata.SyncData
for {
value = stream.Value().(Value)
value = stream.Value().(syncdata.SyncData)
if value.VersionRef >= versionRef {
break
}

View File

@ -0,0 +1,5 @@
package syncdata
type SyncData struct {
VersionRef int `json:"version"`
}