chore: reorder api package structure
This commit is contained in:
@@ -3,6 +3,8 @@ package middleware
|
||||
import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"orbits-server/internal/api/response"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -36,11 +38,23 @@ func SlogMiddleware(logger *slog.Logger) gin.HandlerFunc {
|
||||
|
||||
func AuthMiddleware() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
orbitsKey := c.GetHeader("orbits-key")
|
||||
if len(orbitsKey) == 0 {
|
||||
c.AbortWithStatus(http.StatusUnauthorized)
|
||||
authorizationHeader := c.GetHeader("Authorization")
|
||||
if len(authorizationHeader) == 0 {
|
||||
c.AbortWithStatusJSON(http.StatusUnauthorized, response.BasicResponse{
|
||||
Msg: "Authorization header is required",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
headerParts := strings.Split(authorizationHeader, " ")
|
||||
if len(headerParts) != 2 || headerParts[0] != "Bearer" {
|
||||
c.AbortWithStatusJSON(http.StatusUnauthorized, response.BasicResponse{
|
||||
Msg: "Authorization header is invalid",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
givenKey := headerParts[1]
|
||||
slog.Info(givenKey)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user