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:
+8
-2
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user