refactoring
This commit is contained in:
parent
3efbb82b88
commit
b2d3e38236
@ -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
11
server/app/appconfig.go
Normal file
@ -0,0 +1,11 @@
|
||||
package app
|
||||
|
||||
type AppConfig struct {
|
||||
DataDir string
|
||||
}
|
||||
|
||||
func NewAppConfig() AppConfig {
|
||||
return AppConfig{
|
||||
DataDir: "data/",
|
||||
}
|
||||
}
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user