运行服务的返回类型为 :http.Handler 。gin.New(),gin.Default() 返回的就是此类型。
使用&http.Server{....} 设置服务参数
使用g.Go(func () error{ return server.ListenAndServe()}) 开启一个服务。
package main
import (
"github.com/Unknwon/log"
"github.com/gin-gonic/gin"
_ "github.com/jinzhu/gorm/dialects/mysql"
"golang.org/x/sync-master/errgroup"
"net/http"
"time"
)
var (g errgroup.Group)
func router01() http.Handler {
r := gin.New()
r.Use(gin.Recovery())
r.GET("/", func(c *gin.Context){
c.JSON(http.StatusOK,gin.H{"code":http.StatusOK,
"error":"Welcome 01"})
})
return r
}
func router02() http.Handler {
r:=gin.New()
r.Use(gin.Recovery())
r.GET("/", func(c *gin.Context) {
c.JSON(http.StatusOK,
gin.H{"code":http.StatusOK,
"error":"Welcome server 02"})
})
return r
}
func main() {
server01 := &h