-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
62 lines (51 loc) · 1.37 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
58
59
60
61
62
package main
import (
"log"
config "github.com/antklim/go-micro-auth/config"
handler "github.com/antklim/go-micro-auth/handler/auth"
proto "github.com/antklim/go-micro-auth/proto/auth"
"github.com/micro/cli"
micro "github.com/micro/go-micro"
)
var (
// Version of the service
Version string
// Build number of the service
Build string
)
func initServiceConfig(c *cli.Context) {
config.Source = c.String("config")
config.FilePath = c.String("config_path")
}
func main() {
log.Printf("Service Version: %s\n", Version)
log.Printf("Service Build: %s\n", Build)
service := micro.NewService(
micro.Name("go.micro.srv.auth"),
micro.Version(Version),
micro.Flags(
cli.StringFlag{
Name: "config",
EnvVar: "CONFIG",
Usage: "Service configuration source, available options `consul` or `file`",
},
cli.StringFlag{
Name: "config_path",
EnvVar: "CONFIG_PATH",
Usage: "Configuration file path, read only in case of `file` config source",
},
),
micro.Action(initServiceConfig),
)
service.Init()
// `config` Init() should be called after service init
// All `config` variables are set on service init action
configHandler, err := config.Init()
if err != nil {
log.Fatal(err)
}
proto.RegisterAuthHandler(service.Server(), &handler.Auth{ConfigHandler: configHandler})
if err := service.Run(); err != nil {
log.Fatal(err)
}
}