File size: 625 Bytes
216f5cb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
package middleware
import (
"pplx2api/config"
"strings"
"github.com/gin-gonic/gin"
)
// AuthMiddleware initializes the Claude client from the request header
func AuthMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
Key := c.GetHeader("Authorization")
if Key != "" {
Key = strings.TrimPrefix(Key, "Bearer ")
if Key != config.ConfigInstance.APIKey {
c.JSON(401, gin.H{
"error": "Invalid API key",
})
c.Abort()
return
}
c.Next()
return
}
c.JSON(401, gin.H{
"error": "Missing or invalid Authorization header",
})
c.Abort()
}
}
|