implement JWT tokens, regenerate docs and sqlc
This commit is contained in:
+24
-2
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user