shotgun/main.go

45 lines
962 B
Go
Raw Normal View History

2024-01-27 14:02:10 -06:00
package main
import (
2024-02-01 08:26:27 -06:00
"context"
2024-01-27 14:02:10 -06:00
"net/http"
"github.com/go-chi/chi/v5"
2024-02-01 08:26:27 -06:00
"gitlab.com/zephyrtronium/sq"
2024-01-27 14:02:10 -06:00
"git.sunturtle.xyz/studio/shotgun/lobby"
2024-02-01 21:02:30 -06:00
"git.sunturtle.xyz/studio/shotgun/player"
2024-01-27 14:02:10 -06:00
"git.sunturtle.xyz/studio/shotgun/serve"
2024-02-01 08:26:27 -06:00
_ "modernc.org/sqlite"
2024-01-27 14:02:10 -06:00
)
func main() {
2024-02-01 08:26:27 -06:00
sessiondb, err := sq.Open("sqlite", ":memory:")
if err != nil {
panic(err)
}
sessions, err := sessiondb.Conn(context.Background())
if err != nil {
panic(err)
}
2024-02-01 21:02:30 -06:00
if err := player.InitSessions(context.Background(), sessions); err != nil {
panic(err)
}
if err := player.InitUsers(context.Background(), sessions); err != nil {
panic(err)
}
s := Server{
l: lobby.New(),
creds: sessions,
sessions: sessions,
}
2024-01-27 14:02:10 -06:00
r := chi.NewRouter()
2024-02-01 21:02:30 -06:00
r.Post("/user/register", s.Register)
2024-02-01 20:40:59 -06:00
r.Post("/user/login", s.Login)
r.With(serve.WithSession(sessions)).Get("/user/me", s.Me)
r.With(serve.WithSession(sessions)).Get("/queue", s.Queue)
2024-01-27 14:02:10 -06:00
http.ListenAndServe(":8080", r)
}