maps-service/server.go

56 lines
1.2 KiB
Go
Raw Permalink Normal View History

2024-11-26 01:22:45 +00:00
package main
import (
"context"
"log"
"net/http"
2024-11-26 22:03:47 +00:00
"git.itzana.me/strafesnet/maps-service/api"
"git.itzana.me/strafesnet/maps-service/internal/controller/submissions"
"git.itzana.me/strafesnet/maps-service/internal/controller/users"
2024-11-26 23:08:40 +00:00
"git.itzana.me/strafesnet/maps-service/internal/datastore/gormstore"
2024-11-26 01:22:45 +00:00
)
type apiServer struct {
2024-11-26 22:03:47 +00:00
submissions *submissions.Submissions
users *users.Users
2024-11-26 01:22:45 +00:00
}
// GetUserRank implements api.Handler.
2024-11-26 22:03:47 +00:00
func (m *apiServer) GetSubmission(ctx context.Context, params api.GetSubmissionParams) (*api.Submission, error) {
2024-11-26 22:10:30 +00:00
return m.submissions.Get(ctx,params)
2024-11-26 01:22:45 +00:00
}
// NewError implements api.Handler.
func (m *apiServer) NewError(ctx context.Context, err error) *api.ErrorStatusCode {
return &api.ErrorStatusCode{
StatusCode: 500,
Response: api.Error{Message: err.Error()},
}
}
func main() {
2024-11-26 23:08:40 +00:00
db, err := gormstore.New(true)
2024-11-26 01:22:45 +00:00
if err != nil {
2024-11-26 23:08:40 +00:00
log.WithField("error", err).Fatalln("database startup failed")
return
2024-11-26 01:22:45 +00:00
}
svc := &apiServer{
2024-11-26 23:14:06 +00:00
submissions: db.Submissions(),
users: db.Users(),
2024-11-26 01:22:45 +00:00
}
srv, err := api.NewServer(
svc,
api.WithPathPrefix("/v2"),
)
if err != nil {
log.Fatal(err)
}
if err := http.ListenAndServe(":8080", srv); err != nil {
log.Fatal(err)
}
}