优化gin

This commit is contained in:
suguo.yao 2021-12-03 14:00:37 +08:00
parent 054cbb910e
commit 1ceea92959
2 changed files with 12 additions and 3 deletions

View File

@ -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,

View File

@ -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`)