Initial commit

This commit is contained in:
2025-03-20 22:23:25 -03:00
parent d4a696a5fb
commit bc675abb58
8 changed files with 241 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
package handlers
import (
"net/http"
"github.com/gin-gonic/gin"
)
// PingHandler responds with a JSON message "pong".
func PingHandler(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "pong"})
}

View File

@@ -0,0 +1,28 @@
package middleware
import (
"net/http"
"strings"
"github.com/gin-gonic/gin"
)
// JWTAuthMiddleware is a simple JWT authentication middleware.
func JWTAuthMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
authHeader := c.GetHeader("Authorization")
if authHeader == "" || !strings.HasPrefix(authHeader, "Bearer ") {
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "Missing or invalid token"})
return
}
token := strings.TrimPrefix(authHeader, "Bearer ")
// For demonstration, accept the token "valid-token" as valid.
if token != "valid-token" {
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "Invalid token"})
return
}
c.Next()
}
}

View File

@@ -0,0 +1,5 @@
package models
type Database interface {
execute() []map[string]interface{}
}

14
internal/routes/routes.go Normal file
View File

@@ -0,0 +1,14 @@
package routes
import (
"Tasker_API/internal/handlers"
"github.com/gin-gonic/gin"
)
// InitializeRoutes sets up the API routes.
func InitializeRoutes(router *gin.Engine) {
// Health check endpoint
router.GET("/ping", handlers.PingHandler)
}