wp-go/middleware/validateservername.go
2022-11-15 16:36:21 +08:00

24 lines
505 B
Go

package middleware
import (
"github.com/gin-gonic/gin"
"github/fthvgb1/wp-go/config"
"github/fthvgb1/wp-go/helper"
"net/http"
"strings"
)
func ValidateServerNames() func(ctx *gin.Context) {
serverName := helper.SimpleSliceToMap(config.Conf.Load().TrustServerNames, func(v string) string {
return v
})
return func(c *gin.Context) {
if len(serverName) > 0 {
if _, ok := serverName[strings.Split(c.Request.Host, ":")[0]]; !ok {
c.Status(http.StatusForbidden)
c.Abort()
}
}
}
}