From 3efbb82b88d8c269ef0bee4a96801290caffee6f Mon Sep 17 00:00:00 2001 From: Settel Date: Sat, 31 Jul 2021 09:55:43 +0200 Subject: [PATCH] refactoring --- server/app/app.go | 15 +++++++++++++++ server/knyt.go | 16 +++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 server/app/app.go diff --git a/server/app/app.go b/server/app/app.go new file mode 100644 index 0000000..257d316 --- /dev/null +++ b/server/app/app.go @@ -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{} +} diff --git a/server/knyt.go b/server/knyt.go index b6fb893..6c700d4 100644 --- a/server/knyt.go +++ b/server/knyt.go @@ -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")