tsk-3: Add Token support (#10)

Closes #3

Reviewed-on: phoenix/textsender-api#10
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
phoenix
2025-11-04 17:51:35 +00:00
committed by phoenix
parent 96fc87ea5e
commit d332cde84f
8 changed files with 113 additions and 4 deletions
+8 -2
View File
@@ -18,13 +18,17 @@ import (
"git.kundeng.us/phoenix/textsender-api/internal/handler"
"git.kundeng.us/phoenix/textsender-api/internal/handler/endpoint"
mdlware "git.kundeng.us/phoenix/textsender-api/internal/middleware"
"git.kundeng.us/phoenix/textsender-api/internal/services"
"git.kundeng.us/phoenix/textsender-api/internal/store"
)
func main() {
cfg := config.Load()
if cfg == nil {
fmt.Errorf("Error initializing config")
fmt.Println("Error initializing config")
os.Exit(-1)
} else if cfg.JWTSecret == "" {
fmt.Println("Error: JWTSecret not initialized")
os.Exit(-1)
}
@@ -45,6 +49,8 @@ func main() {
return
}
jwtService := services.NewJWTService(cfg.JWTSecret)
contactStore := store.NewContactStore(database.Pool)
contactHandler := handler.NewContactHandler(contactStore)
@@ -55,7 +61,7 @@ func main() {
router.Use(middleware.Timeout(60 * time.Second))
router.Use(mdlware.JSONContentType)
router.Post(endpoint.ADD_CONTACT_ENDPOINT, contactHandler.AddContact)
router.Handle(endpoint.ADD_CONTACT_ENDPOINT, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(contactHandler.AddContact)))
// Start server
server := &http.Server{