优化gin
This commit is contained in:
parent
054cbb910e
commit
1ceea92959
|
|
@ -10,9 +10,16 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func Service(conf *Config) {
|
func Service(conf *Config) {
|
||||||
|
if conf == nil {
|
||||||
|
conf = &Config{
|
||||||
|
RootPath: "/",
|
||||||
|
Addr: "0.0.0.0",
|
||||||
|
Port: 80,
|
||||||
|
}
|
||||||
|
}
|
||||||
go func() {
|
go func() {
|
||||||
router := gin.New()
|
router := gin.New()
|
||||||
routerSetup(router)
|
routerSetup(router, &conf.RootPath)
|
||||||
s := &http.Server{
|
s := &http.Server{
|
||||||
Addr: fmt.Sprintf("%s:%d", conf.Addr, conf.Port),
|
Addr: fmt.Sprintf("%s:%d", conf.Addr, conf.Port),
|
||||||
Handler: router,
|
Handler: router,
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,17 @@
|
||||||
package gin
|
package gin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
//路由配置
|
//路由配置
|
||||||
func routerSetup(router *gin.Engine) {
|
func routerSetup(router *gin.Engine, rootpath *string) {
|
||||||
router.Use(gin.Recovery())
|
router.Use(gin.Recovery())
|
||||||
router.GET(`/health/check`)
|
router.GET(`/health/check`)
|
||||||
|
|
||||||
r := router.Group(`/user`)
|
r := router.Group(fmt.Sprintf("/%s", *rootpath))
|
||||||
{
|
{
|
||||||
r.POST(`/register`)
|
r.POST(`/register`)
|
||||||
r.GET(`/accountcheck/:accname`)
|
r.GET(`/accountcheck/:accname`)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue