router created
This commit is contained in:
parent
5761bf88c6
commit
875e4eefbd
1 changed files with 29 additions and 0 deletions
29
internal/router/handler.go
Normal file
29
internal/router/handler.go
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package router
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func SetRouter(mode string) *gin.Engine {
|
||||
if mode == "release" {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
} else {
|
||||
gin.SetMode(gin.DebugMode)
|
||||
}
|
||||
|
||||
engine := gin.Default()
|
||||
if mode == "release" {
|
||||
err := engine.SetTrustedProxies([]string{"172.20.0.0/16"})
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Router | Set proxies failed")
|
||||
}
|
||||
}
|
||||
|
||||
engine.NoRoute(func(c *gin.Context) {
|
||||
c.Status(http.StatusForbidden)
|
||||
})
|
||||
|
||||
return engine
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue