forked from kkszysiu/user-srv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
39 lines (32 loc) · 745 Bytes
/
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
package main
import (
"log"
"github.com/micro/cli"
"github.com/micro/go-micro"
"github.com/micro/user-srv/db"
"github.com/micro/user-srv/handler"
proto "github.com/micro/user-srv/proto/account"
)
func main() {
service := micro.NewService(
micro.Name("go.micro.srv.user"),
micro.Flags(
cli.StringFlag{
Name: "database_url",
EnvVar: "DATABASE_URL",
Usage: "The database URL e.g root@tcp(127.0.0.1:3306)/user",
},
),
micro.Action(func(c *cli.Context) {
if len(c.String("database_url")) > 0 {
db.Url = c.String("database_url")
}
}),
)
service.Init()
db.Init()
proto.RegisterAccountHandler(service.Server(), new(handler.Account))
if err := service.Run(); err != nil {
log.Fatal(err)
}
}