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 ( import (
"fmt" "fmt"
"net/http" "net/http"
"sirlab.de/go/knyt/app"
"sirlab.de/go/knyt/engine" "sirlab.de/go/knyt/engine"
"sirlab.de/go/knyt/handler" "sirlab.de/go/knyt/handler"
) )
func main() { func main() {
app := handler.NewAuthMux() app := app.NewApp()
http.Handle("/", app) 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 // default handler
fsHandler := http.FileServer(http.Dir("../client/dist/")) fsHandler := http.FileServer(http.Dir("../client/dist/"))
app.PublicHandle("/", fsHandler) app.Mux.PublicHandle("/", fsHandler)
eng := engine.NewEngine() app.Mux.PublicHandleFunc("/api/sync", app.Eng.GetHttpHandler())
app.PublicHandleFunc("/api/sync", eng.GetHttpHandler()) go app.Eng.Run()
go eng.Run()
// start listening // start listening
fmt.Println("http://localhost:32039") fmt.Println("http://localhost:32039")