refactoring
This commit is contained in:
parent
8231bda18b
commit
59a81fd73e
@ -1,14 +1,12 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"sirlab.de/go/knyt/engine"
|
||||
"sirlab.de/go/knyt/handler"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
Config AppConfig
|
||||
Mux *handler.AuthMux
|
||||
Eng *engine.Engine
|
||||
}
|
||||
|
||||
func NewApp(config AppConfig) *App {
|
||||
|
@ -7,13 +7,18 @@ import (
|
||||
type HandlerFunc func(http.ResponseWriter, *http.Request)
|
||||
|
||||
type AuthMux struct {
|
||||
mux *http.ServeMux
|
||||
mux *http.ServeMux
|
||||
Port int
|
||||
}
|
||||
|
||||
func NewAuthMux() *AuthMux {
|
||||
return &(AuthMux{
|
||||
mux: http.NewServeMux(),
|
||||
})
|
||||
mux := AuthMux{
|
||||
mux: http.NewServeMux(),
|
||||
Port: 32039,
|
||||
}
|
||||
http.Handle("/", mux.mux)
|
||||
|
||||
return &mux
|
||||
}
|
||||
|
||||
func (authMux *AuthMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
@ -27,3 +32,7 @@ func (authMux *AuthMux) PublicHandleFunc(pattern string, handlerFunc HandlerFunc
|
||||
func (authMux *AuthMux) PublicHandle(pattern string, handler http.Handler) {
|
||||
authMux.mux.Handle(pattern, handler)
|
||||
}
|
||||
|
||||
func (authMux *AuthMux) ListenAndServe() {
|
||||
http.ListenAndServe(":32039", nil)
|
||||
}
|
||||
|
@ -4,35 +4,21 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sirlab.de/go/knyt/app"
|
||||
"sirlab.de/go/knyt/engine"
|
||||
"sirlab.de/go/knyt/handler"
|
||||
"sirlab.de/go/knyt/user"
|
||||
"sirlab.de/go/knyt/users"
|
||||
)
|
||||
|
||||
func main() {
|
||||
appConfig := app.NewAppConfig()
|
||||
App := app.NewApp(appConfig)
|
||||
App.Mux = handler.NewAuthMux()
|
||||
App.Eng = engine.NewEngine()
|
||||
http.Handle("/", App.Mux)
|
||||
|
||||
usrs := users.NewUsers()
|
||||
u1 := user.NewUser("123", "Volkmar", user.ROLE_PLAYER)
|
||||
u2 := user.NewUser("123", "Annabell", user.ROLE_GAMEMASTER)
|
||||
usrs.AddUser(u1)
|
||||
usrs.AddUser(u2)
|
||||
|
||||
App.Mux.PublicHandleFunc("/__intern__/exit", handler.Exit)
|
||||
|
||||
// default handler
|
||||
fsHandler := http.FileServer(http.Dir("../client/dist/"))
|
||||
fsHandler := http.FileServer(http.Dir("../../client/dist/"))
|
||||
App.Mux.PublicHandle("/", fsHandler)
|
||||
|
||||
App.Mux.PublicHandleFunc("/api/sync", App.Eng.GetHttpHandler())
|
||||
go App.Eng.Run()
|
||||
|
||||
// start listening
|
||||
fmt.Println("http://localhost:32039")
|
||||
http.ListenAndServe(":32039", nil)
|
||||
fmt.Printf("http://localhost:%d/\n", App.Mux.Port)
|
||||
App.Mux.ListenAndServe()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user