refactoring

This commit is contained in:
Settel 2021-07-31 09:55:43 +02:00
parent 8bee534e60
commit 3efbb82b88
2 changed files with 24 additions and 7 deletions

15
server/app/app.go Normal file
View File

@ -0,0 +1,15 @@
package app
import (
"sirlab.de/go/knyt/engine"
"sirlab.de/go/knyt/handler"
)
type App struct {
Mux *handler.AuthMux
Eng *engine.Engine
}
func NewApp() *App {
return &App{}
}

View File

@ -3,23 +3,25 @@ package main
import (
"fmt"
"net/http"
"sirlab.de/go/knyt/app"
"sirlab.de/go/knyt/engine"
"sirlab.de/go/knyt/handler"
)
func main() {
app := handler.NewAuthMux()
http.Handle("/", app)
app := app.NewApp()
app.Mux = handler.NewAuthMux()
app.Eng = engine.NewEngine()
http.Handle("/", app.Mux)
app.PublicHandleFunc("/__intern__/exit", handler.Exit)
app.Mux.PublicHandleFunc("/__intern__/exit", handler.Exit)
// default handler
fsHandler := http.FileServer(http.Dir("../client/dist/"))
app.PublicHandle("/", fsHandler)
app.Mux.PublicHandle("/", fsHandler)
eng := engine.NewEngine()
app.PublicHandleFunc("/api/sync", eng.GetHttpHandler())
go eng.Run()
app.Mux.PublicHandleFunc("/api/sync", app.Eng.GetHttpHandler())
go app.Eng.Run()
// start listening
fmt.Println("http://localhost:32039")