refactoring

This commit is contained in:
Settel 2021-07-31 10:18:01 +02:00
parent 3efbb82b88
commit b2d3e38236
3 changed files with 27 additions and 12 deletions

View File

@ -6,10 +6,13 @@ import (
) )
type App struct { type App struct {
Mux *handler.AuthMux Config AppConfig
Eng *engine.Engine Mux *handler.AuthMux
Eng *engine.Engine
} }
func NewApp() *App { func NewApp(config AppConfig) *App {
return &App{} return &App{
Config: config,
}
} }

11
server/app/appconfig.go Normal file
View File

@ -0,0 +1,11 @@
package app
type AppConfig struct {
DataDir string
}
func NewAppConfig() AppConfig {
return AppConfig{
DataDir: "data/",
}
}

View File

@ -9,19 +9,20 @@ import (
) )
func main() { func main() {
app := app.NewApp() appConfig := app.NewAppConfig()
app.Mux = handler.NewAuthMux() App := app.NewApp(appConfig)
app.Eng = engine.NewEngine() App.Mux = handler.NewAuthMux()
http.Handle("/", app.Mux) App.Eng = engine.NewEngine()
http.Handle("/", App.Mux)
app.Mux.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.Mux.PublicHandle("/", fsHandler) App.Mux.PublicHandle("/", fsHandler)
app.Mux.PublicHandleFunc("/api/sync", app.Eng.GetHttpHandler()) App.Mux.PublicHandleFunc("/api/sync", App.Eng.GetHttpHandler())
go app.Eng.Run() go App.Eng.Run()
// start listening // start listening
fmt.Println("http://localhost:32039") fmt.Println("http://localhost:32039")