Files
HY2XS_flamy/apps/middleware/local_only.go
T

27 lines
434 B
Go

package middleware
import (
"net"
"net/http"
"github.com/gin-gonic/gin"
"hy2xs-admin/model/vo"
)
func LocalOnlyHandler() gin.HandlerFunc {
return func(c *gin.Context) {
host, _, err := net.SplitHostPort(c.Request.RemoteAddr)
if err != nil {
host = c.ClientIP()
}
if host != "127.0.0.1" && host != "::1" {
vo.Fail("local access only", c)
c.AbortWithStatus(http.StatusForbidden)
return
}
c.Next()
}
}