ai-css/middleware/login_direct/login.go

32 lines
517 B
Go

package login_direct
import (
"net/http"
"strings"
"github.com/gin-gonic/gin"
)
func DomainAuthRedirectMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
host := c.Request.Host
// 只针对 admin 域名
if strings.HasPrefix(host, "admin.example.com") {
// 这里写你的认证逻辑
token := c.GetHeader("Authorization")
if token == "" {
// 未认证跳转
c.Redirect(http.StatusFound, "https://admin.example.com/login")
c.Abort()
return
}
}
c.Next()
}
}