2021-07-28 20:21:14 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-07-28 21:17:08 +00:00
|
|
|
"github.com/imkira/go-observer"
|
2021-07-28 20:21:14 +00:00
|
|
|
"net/http"
|
|
|
|
"sirlab.de/go/knyc/handler"
|
2021-07-28 21:17:08 +00:00
|
|
|
"time"
|
2021-07-28 20:21:14 +00:00
|
|
|
)
|
|
|
|
|
2021-07-28 21:17:08 +00:00
|
|
|
type Engine struct {
|
2021-07-29 16:39:12 +00:00
|
|
|
obs observer.Property
|
2021-07-28 21:17:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var engine Engine
|
|
|
|
|
|
|
|
func (engine Engine) runEngine() {
|
|
|
|
for {
|
2021-07-29 16:39:12 +00:00
|
|
|
value := engine.obs.Value().(handler.Value)
|
|
|
|
fmt.Printf("sleep: %d\n", value.Value)
|
2021-07-28 21:17:08 +00:00
|
|
|
time.Sleep(1 * time.Second)
|
2021-07-29 16:39:12 +00:00
|
|
|
value.Value++
|
|
|
|
engine.obs.Update(value)
|
2021-07-28 21:17:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-28 20:21:14 +00:00
|
|
|
func main() {
|
|
|
|
app := handler.NewAuthMux()
|
|
|
|
http.Handle("/", app)
|
|
|
|
|
|
|
|
app.PublicHandleFunc("/__intern__/exit", handler.Exit)
|
|
|
|
|
2021-07-29 16:39:12 +00:00
|
|
|
obs := observer.NewProperty(handler.Value{Value: 19})
|
|
|
|
app.PublicHandleFunc("/sync", handler.SyncFactory(obs))
|
2021-07-28 21:17:08 +00:00
|
|
|
|
2021-07-28 20:21:14 +00:00
|
|
|
// hanlde login page
|
|
|
|
fsHandler := http.FileServer(http.Dir("../client/dist/"))
|
2021-07-28 21:17:08 +00:00
|
|
|
|
2021-07-28 20:21:14 +00:00
|
|
|
// default handler
|
|
|
|
app.PublicHandle("/", fsHandler)
|
|
|
|
|
2021-07-29 16:39:12 +00:00
|
|
|
engine.obs = obs
|
2021-07-28 21:17:08 +00:00
|
|
|
go engine.runEngine()
|
|
|
|
|
2021-07-28 20:21:14 +00:00
|
|
|
// start listening
|
|
|
|
fmt.Println("http://localhost:32039")
|
|
|
|
http.ListenAndServe(":32039", nil)
|
|
|
|
}
|