-
Notifications
You must be signed in to change notification settings - Fork 13
/
run.go
36 lines (32 loc) · 943 Bytes
/
run.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package core
import (
"github.com/gin-gonic/gin"
"github.com/panco95/go-garden/core/log"
)
// Run service start
func (g *Garden) Run(route func(r *gin.Engine), rpc interface{}, auth func() gin.HandlerFunc) {
go g.runHttpServer(route, auth)
go g.runRpcServer(rpc)
forever := make(chan int, 0)
<-forever
}
func (g *Garden) runHttpServer(route func(r *gin.Engine), auth func() gin.HandlerFunc) {
address := g.GetServiceIp()
if g.cfg.Service.HttpOut {
address = "0.0.0.0"
}
listenAddress := address + ":" + g.cfg.Service.HttpPort
if err := g.ginListen(listenAddress, route, auth); err != nil {
log.Fatal("gin", err)
}
}
func (g *Garden) runRpcServer(rpc interface{}) {
address := g.GetServiceIp()
if g.cfg.Service.RpcOut {
address = "0.0.0.0"
}
rpcAddress := address + ":" + g.cfg.Service.RpcPort
if err := g.rpcListen(g.cfg.Service.ServiceName, "tcp", rpcAddress, rpc, ""); err != nil {
log.Fatal("rpcRun", err)
}
}