diff --git a/gin/gin.go b/gin/gin.go index ad1b2a4..826af5e 100644 --- a/gin/gin.go +++ b/gin/gin.go @@ -10,9 +10,16 @@ import ( ) func Service(conf *Config) { + if conf == nil { + conf = &Config{ + RootPath: "/", + Addr: "0.0.0.0", + Port: 80, + } + } go func() { router := gin.New() - routerSetup(router) + routerSetup(router, &conf.RootPath) s := &http.Server{ Addr: fmt.Sprintf("%s:%d", conf.Addr, conf.Port), Handler: router, diff --git a/gin/router.go b/gin/router.go index 5fa320b..677bc7b 100644 --- a/gin/router.go +++ b/gin/router.go @@ -1,15 +1,17 @@ package gin import ( + "fmt" + "github.com/gin-gonic/gin" ) //路由配置 -func routerSetup(router *gin.Engine) { +func routerSetup(router *gin.Engine, rootpath *string) { router.Use(gin.Recovery()) router.GET(`/health/check`) - r := router.Group(`/user`) + r := router.Group(fmt.Sprintf("/%s", *rootpath)) { r.POST(`/register`) r.GET(`/accountcheck/:accname`)