-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (44 loc) · 1.09 KB
/
main.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"log"
"os"
"github.com/mrgAndysm/mic_user/protouser"
"github.com/mrgAndysm/mic_user/service/grpc"
"github.com/mrgAndysm/mic_user/apps/routers"
"github.com/mrgAndysm/mic_user/com"
micro "github.com/micro/go-micro/v2"
"github.com/micro/go-micro/v2/web"
)
func main() {
// consul 注册服务
c := new(com.ConsulServer)
c.ConsulServerInit()
if os.Args[1] == "w" {
//初始化路由
ginRouter := routers.InitRouters()
// web服务
websrv := web.NewService(
web.Handler(ginRouter),
web.Name("userserver"),
web.Address(":8001"),
web.Handler(ginRouter),
web.Registry(c.ConsulReg),
)
if err := websrv.Run(); err != nil {
log.Fatal(err)
}
} else {
// grpc微服务
srv := micro.NewService(
//micro.Name服务端向consul注册服务名称 客户端需要通过该名称来进行调用
micro.Name("go.micro.svr.user"),
micro.Version("latest"),
micro.Registry(c.ConsulReg),
)
srv.Init()
protouser.RegisterUserServiceHandler(srv.Server(), new(grpc.UserService))
if err := srv.Run(); err != nil {
log.Fatal(err)
}
}
}