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 {
Config AppConfig
Mux *handler.AuthMux
Eng *engine.Engine
}
func NewApp() *App {
return &App{}
func NewApp(config AppConfig) *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() {
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")