-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (47 loc) · 1.44 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
package main
import (
"fmt"
"github.com/micro/go-micro"
// etcd "github.com/micro/go-micro/registry/etcd"
pb "github.com/rickynyairo/shipping-container-platform/user-service/proto/user"
"log"
)
func main() {
// Creates a database connection and handles
// closing it again before exit.
db, err := CreateConnection()
defer db.Close()
if err != nil {
log.Fatalf("Could not connect to DB: %v", err)
}
// Automatically migrates the user struct
// into database columns/types etc. This will
// check for changes and migrate them each time
// this service is restarted.
db.AutoMigrate(&pb.User{})
repo := &UserRepository{db}
tokenService := &TokenService{repo}
// Create a new service. Optionally include some options here.
srv := micro.NewService(
// This name must match the package name given in your protobuf definition
micro.Name("shippy.auth"),
micro.Version("latest"),
// micro.Registry(etcd.NewRegistry()),
)
// Init will parse the command line flags.
srv.Init()
publisher := micro.NewPublisher("user.created", srv.Client())
// // pubsub := srv.Server().Options().Broker
// client := pb.NewUserServiceClient("go.micro.api.greeter", srv.Client())
// srv.Server().Handle(
// srv.Server().NewHandler(
// &Handler{Client: client},
// ),
// )
// Register handler
pb.RegisterAuthHandler(srv.Server(), &Handler{repo, tokenService, publisher})
// Run the server
if err := srv.Run(); err != nil {
fmt.Println(err)
}
}