update to new webserver module

This commit is contained in:
2026-01-10 14:46:49 +11:00
parent 28b7ba34f0
commit a0cd269466
14 changed files with 199 additions and 69 deletions

View File

@@ -25,7 +25,7 @@ func setupAuth(
server,
conn,
logger,
handler.NewErrorPage,
handler.ErrorPage,
)
if err != nil {
return nil, errors.Wrap(err, "hwsauth.NewAuthenticator")

View File

@@ -2,10 +2,12 @@ package main
import (
"database/sql"
"git.haelnorr.com/h/golib/hws"
"io/fs"
"net/http"
"projectreshoot/internal/config"
"projectreshoot/internal/handler"
"git.haelnorr.com/h/golib/hws"
"git.haelnorr.com/h/golib/hlog"
"git.haelnorr.com/h/golib/jwt"
@@ -26,14 +28,14 @@ func setupHttpServer(
httpServer, err := hws.NewServer(
config.Host,
config.Port,
config.ReadHeaderTimeout,
config.WriteTimeout,
config.IdleTimeout,
config.GZIP,
)
if err != nil {
return nil, errors.Wrap(err, "hws.NewServer")
}
httpServer.ReadHeaderTimeout(config.ReadHeaderTimeout)
httpServer.WriteTimeout(config.WriteTimeout)
httpServer.IdleTimeout(config.IdleTimeout)
httpServer.GZIP = config.GZIP
ignoredPaths := []string{
"/static/css/output.css",
@@ -45,6 +47,11 @@ func setupHttpServer(
return nil, errors.Wrap(err, "setupAuth")
}
err = httpServer.AddErrorPage(handler.ErrorPage)
if err != nil {
return nil, errors.Wrap(err, "httpServer.AddErrorPage")
}
err = httpServer.AddLogger(logger)
if err != nil {
return nil, errors.Wrap(err, "httpServer.AddLogger")

View File

@@ -114,7 +114,7 @@ func addRoutes(
{
Path: "/movie/{movie_id}",
Method: hws.MethodGET,
Handler: handler.Movie(config, logger),
Handler: handler.Movie(server, config),
},
}

View File

@@ -67,7 +67,7 @@ func run(ctx context.Context, w io.Writer, args map[string]string, config *confi
// Runs the http server
logger.Debug().Msg("Starting up the HTTP server")
err = httpServer.Start()
err = httpServer.Start(ctx)
if err != nil {
return errors.Wrap(err, "httpServer.Start")
}
@@ -79,7 +79,10 @@ func run(ctx context.Context, w io.Writer, args map[string]string, config *confi
shutdownCtx := context.Background()
shutdownCtx, cancel := context.WithTimeout(shutdownCtx, 10*time.Second)
defer cancel()
httpServer.Shutdown(shutdownCtx)
err := httpServer.Shutdown(shutdownCtx)
if err != nil {
logger.Error().Err(err).Msg("Graceful shutdown failed")
}
})
wg.Wait()
logger.Info().Msg("Shutting down")