/
main.go
41 lines (31 loc) · 828 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
40
41
package main
import (
"context"
"log"
"os"
pb "github.com/KathurimaKimathi/shippy/shippy-service-vessel/proto/vessel"
"github.com/micro/go-micro/v2"
)
func main() {
service := micro.NewService(
micro.Name("shippy.service.vessel"),
)
service.Init()
uri := os.Getenv("DB_HOST")
client, err := CreateClient(context.Background(), uri, 0)
if err != nil {
log.Panic(err)
}
defer client.Disconnect(context.Background())
//creating vessel collection in the Database
vesselCollection := client.Database("shippy").Collection("vessels")
repository := &MongoRepository{vesselCollection}
h := &handler{repository}
// Register our implementation with
if err := pb.RegisterVesselServiceHandler(service.Server(), h); err != nil {
log.Panic(err)
}
if err := service.Run(); err != nil {
log.Panic(err)
}
}