chore: reorder api package structure

This commit is contained in:
DaanSelen
2026-04-23 15:43:39 +02:00
parent ea2a1730a4
commit 0556bc4932
6 changed files with 56 additions and 39 deletions
+17 -3
View File
@@ -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)
}
}