From b2d3e38236f346dc67bb1f12b2f71dac19f84299 Mon Sep 17 00:00:00 2001 From: Settel Date: Sat, 31 Jul 2021 10:18:01 +0200 Subject: [PATCH] refactoring --- server/app/app.go | 11 +++++++---- server/app/appconfig.go | 11 +++++++++++ server/knyt.go | 17 +++++++++-------- 3 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 server/app/appconfig.go diff --git a/server/app/app.go b/server/app/app.go index 257d316..1321b5a 100644 --- a/server/app/app.go +++ b/server/app/app.go @@ -6,10 +6,13 @@ import ( ) type App struct { - Mux *handler.AuthMux - Eng *engine.Engine + Config AppConfig + Mux *handler.AuthMux + Eng *engine.Engine } -func NewApp() *App { - return &App{} +func NewApp(config AppConfig) *App { + return &App{ + Config: config, + } } diff --git a/server/app/appconfig.go b/server/app/appconfig.go new file mode 100644 index 0000000..15ea124 --- /dev/null +++ b/server/app/appconfig.go @@ -0,0 +1,11 @@ +package app + +type AppConfig struct { + DataDir string +} + +func NewAppConfig() AppConfig { + return AppConfig{ + DataDir: "data/", + } +} diff --git a/server/knyt.go b/server/knyt.go index 6c700d4..783279b 100644 --- a/server/knyt.go +++ b/server/knyt.go @@ -9,19 +9,20 @@ import ( ) func main() { - app := app.NewApp() - app.Mux = handler.NewAuthMux() - app.Eng = engine.NewEngine() - http.Handle("/", app.Mux) + appConfig := app.NewAppConfig() + App := app.NewApp(appConfig) + App.Mux = handler.NewAuthMux() + App.Eng = engine.NewEngine() + http.Handle("/", App.Mux) - app.Mux.PublicHandleFunc("/__intern__/exit", handler.Exit) + App.Mux.PublicHandleFunc("/__intern__/exit", handler.Exit) // default handler fsHandler := http.FileServer(http.Dir("../client/dist/")) - app.Mux.PublicHandle("/", fsHandler) + App.Mux.PublicHandle("/", fsHandler) - app.Mux.PublicHandleFunc("/api/sync", app.Eng.GetHttpHandler()) - go app.Eng.Run() + App.Mux.PublicHandleFunc("/api/sync", App.Eng.GetHttpHandler()) + go App.Eng.Run() // start listening fmt.Println("http://localhost:32039")