package global import ( "io" "net/http" "github.com/gin-gonic/gin" log "github.com/sirupsen/logrus" "github.com/smbrave/goutil" ) func InitServer(cfgToml string) { LoadConfig(cfgToml) InitDB() InitRedis() InitStorage() GetGin().NoRoute(func(ctx *gin.Context) { requestUri := ctx.Request.RequestURI requestIp := ctx.GetHeader("x-remote-ip") ignorePath := []string{ "", "/", "/favicon.ico", "/robots.txt", "/.well-known/apple-app-site-association", } if goutil.StrInSlice(requestUri, ignorePath) { return } if ctx.Request.Method == http.MethodPost || ctx.Request.Method == http.MethodPut { body, _ := io.ReadAll(ctx.Request.Body) log.Warnf("no route [%s][%s][%s][%s]\n%s", requestIp, ctx.Request.Host, ctx.Request.Method, requestUri, string(body)) } else { log.Warnf("no route [%s][%s][%s][%s]", requestIp, ctx.Request.Host, ctx.Request.Method, requestUri) } }) }