From 1ceea929591911c7fb00e3ae9400b708a95cb20c Mon Sep 17 00:00:00 2001 From: "suguo.yao" Date: Fri, 3 Dec 2021 14:00:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96gin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gin/gin.go | 9 ++++++++- gin/router.go | 6 ++++-- 2 files changed, 12 insertions(+), 3 deletions(-) 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`)