wip 0.0.5
All checks were successful
CloudSave/pipeline/head This commit looks good

This commit is contained in:
2025-09-02 22:32:07 +02:00
parent 8518503d40
commit 0a33d1b68d
15 changed files with 288 additions and 14 deletions

View File

@@ -21,6 +21,7 @@ type (
Server *http.Server
Service *data.Service
documentRoot string
creds map[string]string
}
)
@@ -32,6 +33,7 @@ func NewServer(documentRoot string, srv *data.Service, creds map[string]string,
s := &HTTPServer{
Service: srv,
documentRoot: documentRoot,
creds: creds,
}
router := chi.NewRouter()
router.NotFound(func(writer http.ResponseWriter, request *http.Request) {
@@ -46,7 +48,7 @@ func NewServer(documentRoot string, srv *data.Service, creds map[string]string,
router.Use(middleware.Compress(5, "application/gzip"))
router.Use(middleware.Heartbeat("/heartbeat"))
router.Route("/api", func(routerAPI chi.Router) {
routerAPI.Use(BasicAuth("cloudsave", creds))
routerAPI.Use(s.BasicAuth("cloudsave"))
routerAPI.Route("/v1", func(r chi.Router) {
// Get information about the server
r.Get("/version", s.Information)
@@ -78,6 +80,10 @@ func NewServer(documentRoot string, srv *data.Service, creds map[string]string,
return s
}
func (s *HTTPServer) SetCredentials(creds map[string]string) {
s.creds = creds
}
func (s HTTPServer) all(w http.ResponseWriter, r *http.Request) {
datastore, err := s.Service.AllGames()
if err != nil {