mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-13 17:47:51 +00:00
feat: add internal stats flush API
This commit is contained in:
26
internal/middleware/internal_auth.go
Normal file
26
internal/middleware/internal_auth.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func InternalAuthMiddleware(expectedToken string) gin.HandlerFunc {
|
||||
expectedToken = strings.TrimSpace(expectedToken)
|
||||
return func(c *gin.Context) {
|
||||
if expectedToken == "" {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
|
||||
token := strings.TrimSpace(c.GetHeader("X-Internal-Token"))
|
||||
if token == "" || token != expectedToken {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "invalid internal token"})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user