getting closer
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2022-11-28 05:09:23 +01:00
parent 75442d261d
commit 5fc22c36b0
7 changed files with 31 additions and 25 deletions

View File

@@ -4,17 +4,17 @@ import (
"context"
"encoding/json"
"net/http"
"time"
"git.eeqj.de/sneak/gohttpserver/internal/database"
"git.eeqj.de/sneak/gohttpserver/internal/globals"
"git.eeqj.de/sneak/gohttpserver/internal/logger"
"github.com/rs/zerolog"
"go.uber.org/fx"
"google.golang.org/genproto/googleapis/spanner/admin/database/v1"
)
type HandlersParams struct {
fx.In
Logger *zerolog.Logger
Logger logger.Logger
Globals globals.Globals
Database database.Database
}
@@ -31,20 +31,12 @@ func New(lc fx.Lifecycle, params HandlersParams) (*Handlers, error) {
lc.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
// FIXME compile some templates here or something
return nil
},
})
return s, nil
}
func (s *Handlers) HandleNow() http.HandlerFunc {
type response struct {
Now time.Time `json:"now"`
}
return func(w http.ResponseWriter, r *http.Request) {
s.respondJSON(w, r, &response{Now: time.Now()}, 200)
}
}
func (s *Handlers) respondJSON(w http.ResponseWriter, r *http.Request, data interface{}, status int) {
w.WriteHeader(status)
w.Header().Set("Content-Type", "application/json")