Initial commit
This commit is contained in:
12
internal/handlers/handlers.go
Normal file
12
internal/handlers/handlers.go
Normal 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"})
|
||||
}
|
||||
28
internal/middleware/auth.go
Normal file
28
internal/middleware/auth.go
Normal 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()
|
||||
}
|
||||
}
|
||||
5
internal/models/database.go
Normal file
5
internal/models/database.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package models
|
||||
|
||||
type Database interface {
|
||||
execute() []map[string]interface{}
|
||||
}
|
||||
14
internal/routes/routes.go
Normal file
14
internal/routes/routes.go
Normal 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)
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user