feat(logger): implement a logger middleware

This commit is contained in:
Julien Dessaux 2024-10-01 08:47:32 +02:00
parent 4ff490806c
commit 2cdbc4e782
Signed by: adyxax
GPG key ID: F92E51B86E07177E
4 changed files with 117 additions and 1 deletions

View file

@ -14,6 +14,7 @@ import (
"time"
"git.adyxax.org/adyxax/tfstated/pkg/database"
"git.adyxax.org/adyxax/tfstated/pkg/logger"
)
type Config struct {
@ -49,7 +50,7 @@ func run(
httpServer := &http.Server{
Addr: net.JoinHostPort(config.Host, config.Port),
Handler: mux,
Handler: logger.Middleware(mux),
}
go func() {
log.Printf("listening on %s\n", httpServer.Addr)

View file

@ -11,6 +11,7 @@ func addRoutes(
db *database.DB,
) {
mux.Handle("GET /healthz", handleHealthz())
mux.Handle("GET /", handleGet(db))
mux.Handle("POST /", handlePost(db))
}