feat: jwt authentication

This commit is contained in:
Robin Dittmar
2026-07-21 13:47:59 +02:00
parent 1cdb0ebefa
commit d9bfcea420
12 changed files with 296 additions and 10 deletions
+5 -4
View File
@@ -76,7 +76,7 @@ func run(serviceName string, serviceVersion string) error {
slog.Error("failed to run migrations", slog.Any("error", err))
}
srv := makeServer(db, cfg.Port)
srv := makeServer(db, cfg)
go func() {
slog.Info("starting http server", "addr", srv.Addr)
if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
@@ -112,14 +112,15 @@ func setupLogging() {
slog.SetDefault(logger)
}
func makeServer(db *sql.DB, port int) *http.Server {
func makeServer(db *sql.DB, cfg *config.Config) *http.Server {
routerConfig := router.Config{
Database: db,
Database: db,
JWTSecret: cfg.JWTSecret,
}
mux := router.NewMux(routerConfig)
srv := &http.Server{
Addr: fmt.Sprintf(":%d", port),
Addr: fmt.Sprintf(":%d", cfg.Port),
Handler: mux,
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,