Initial commit: Material Texture API service
- Go + Gin + GORM + PostgreSQL backend - RESTful API for material management - Docker deployment support - Database partitioning for billion-scale data - API documentation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
32
internal/middleware/auth.go
Normal file
32
internal/middleware/auth.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"material_texture/pkg/response"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
const (
|
||||
HeaderAPIToken = "X-API-Token"
|
||||
)
|
||||
|
||||
// TokenAuth 简单Token认证中间件
|
||||
func TokenAuth(expectedToken string) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
token := c.GetHeader(HeaderAPIToken)
|
||||
|
||||
if token == "" {
|
||||
response.Unauthorized(c, "missing API token")
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
if token != expectedToken {
|
||||
response.Unauthorized(c, "invalid API token")
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user