This commit is contained in:
root
2026-09-19 20:21:47 +02:00
commit 0798933b05
62 changed files with 7658 additions and 0 deletions
+40
View File
@@ -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))
}