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