implement JWT tokens, regenerate docs and sqlc

This commit is contained in:
zardzul
2026-03-14 18:46:48 +01:00
parent 131aee8638
commit d5e608feeb
18 changed files with 441 additions and 82 deletions
+24 -2
View File
@@ -1,6 +1,9 @@
package main
import (
"os"
"strconv"
"time"
"zardzul/music-index/database"
_ "zardzul/music-index/docs"
"zardzul/music-index/handlers"
@@ -28,13 +31,32 @@ func main() {
}
defer pool.Close()
jwtSecret := os.Getenv("JWT_SECRET")
if jwtSecret == "" {
panic("JWT_SECRET is required")
}
jwtIssuer := os.Getenv("JWT_ISSUER")
if jwtIssuer == "" {
jwtIssuer = "music-index-api"
}
jwtTTLMinutes := 60
if envTTL := os.Getenv("JWT_TTL_MINUTES"); envTTL != "" {
parsed, parseErr := strconv.Atoi(envTTL)
if parseErr != nil || parsed <= 0 {
panic("JWT_TTL_MINUTES must be a positive integer")
}
jwtTTLMinutes = parsed
}
userRepo := repository.NewUserRepository(queries)
userHandler := handlers.NewUserHandler(userRepo)
userHandler := handlers.NewUserHandler(userRepo, jwtSecret, jwtIssuer, time.Duration(jwtTTLMinutes)*time.Minute)
artistRepo := repository.NewArtistRepository(queries)
artistHandler := handlers.NewArtistHandler(artistRepo)
router := gin.Default()
routes.Routes(router, userHandler, artistHandler)
routes.Routes(router, userHandler, artistHandler, jwtSecret)
if routerError := router.Run(":8080"); routerError != nil {
panic(routerError)