-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
53 lines (43 loc) · 942 Bytes
/
Copy pathmain.go
File metadata and controls
53 lines (43 loc) · 942 Bytes
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"flag"
"fmt"
"log"
"golang.org/x/sync/errgroup"
"github.com/gin-gonic/gin"
"GinGateway/constant"
"GinGateway/middleware/limiter"
"GinGateway/middleware/router"
"GinGateway/service/discovery"
)
func Init() {
flag.IntVar(&port, "port", 8081, "the port to start gin")
flag.Parse()
// 初始化服务注册和服务发现中心的配置
discovery.InitDiscovery("config.yaml")
}
var (
g errgroup.Group
port int
)
func main() {
Init()
r := gin.New()
r.Use(gin.Recovery(), gin.Logger())
r.Use(limiter.TokenBucketLimiter(constant.BucketLockType_CAS))
r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
r.Use(router.RouteForward("work", constant.HttpType_HTTP))
g.Go(func() error {
return r.Run(fmt.Sprintf(":%d", port))
})
//g.Go(func() error {
// return r.Run(fmt.Sprintf(":%d", port))
//})
if err := g.Wait(); err != nil {
log.Fatal(err)
}
}