mirror of
https://github.com/danielmiessler/Fabric.git
synced 2026-02-12 23:15:05 -05:00
21 lines
380 B
Go
21 lines
380 B
Go
package restapi
|
|
|
|
import (
|
|
"net/http"
|
|
"fmt"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func ApiKeyMiddleware(apiKey string) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
headerApiKey := c.GetHeader("X-API-Key")
|
|
|
|
if headerApiKey != apiKey {
|
|
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": fmt.Sprintf("Wrong or missing API Key")})
|
|
return
|
|
}
|
|
|
|
c.Next()
|
|
}
|
|
} |