init
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
// Command server serves the player HTTP API and the web front end.
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"wh/api"
|
||||
"wh/config"
|
||||
"wh/store"
|
||||
"wh/web"
|
||||
)
|
||||
|
||||
func main() {
|
||||
dsn := flag.String("db", config.DatabaseURL(), "sqlite:<path> or postgres:// URL (default: $DATABASE_URL)")
|
||||
addr := flag.String("addr", ":8080", "listen address")
|
||||
cfg, err := config.Bind(flag.CommandLine)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
flag.Parse()
|
||||
if err := cfg.Validate(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
st, err := store.Open(*dsn)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer st.Close()
|
||||
if err := st.Migrate(context.Background()); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
mux := api.New(st, *cfg)
|
||||
mux.Handle("/", web.Handler()) // the site; API routes are more specific and win
|
||||
log.Printf("listening on %s", *addr)
|
||||
log.Fatal(http.ListenAndServe(*addr, mux))
|
||||
}
|
||||
Reference in New Issue
Block a user