refactoring
This commit is contained in:
parent
3efbb82b88
commit
b2d3e38236
@ -6,10 +6,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type App struct {
|
type App struct {
|
||||||
|
Config AppConfig
|
||||||
Mux *handler.AuthMux
|
Mux *handler.AuthMux
|
||||||
Eng *engine.Engine
|
Eng *engine.Engine
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewApp() *App {
|
func NewApp(config AppConfig) *App {
|
||||||
return &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() {
|
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")
|
||||||
|
Loading…
Reference in New Issue
Block a user