1
0

domainValidator.go 324 B

123456789101112131415161718192021
  1. package middleware
  2. import (
  3. "net/http"
  4. "strings"
  5. "github.com/gin-gonic/gin"
  6. )
  7. func DomainValidatorMiddleware(domain string) gin.HandlerFunc {
  8. return func(c *gin.Context) {
  9. host := strings.Split(c.Request.Host, ":")[0]
  10. if host != domain {
  11. c.AbortWithStatus(http.StatusForbidden)
  12. return
  13. }
  14. c.Next()
  15. }
  16. }