chore: initial import 萌邮 MengPost (React+Vite + Go+Gin)

Made-with: Cursor
This commit is contained in:
2026-04-17 22:27:57 +08:00
commit 0c31a4b376
40 changed files with 4263 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
package middleware
import (
"net/http"
"strings"
"github.com/gin-gonic/gin"
)
// TokenAuth 校验请求头中的 X-Auth-Token 或 Authorization: Bearer <token>.
func TokenAuth(expected string) gin.HandlerFunc {
return func(c *gin.Context) {
got := c.GetHeader("X-Auth-Token")
if got == "" {
auth := c.GetHeader("Authorization")
got = strings.TrimPrefix(auth, "Bearer ")
}
if got == "" || got != expected {
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})
return
}
c.Next()
}
}