-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
65 lines (49 loc) · 1.27 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
63
64
65
package main
import (
"context"
"io/ioutil"
"log"
gateway "github.com/go-code/goinfer/app/gateway"
serving "github.com/go-code/goinfer/app/grpc"
"gopkg.in/yaml.v2"
_ "net/http/pprof"
)
const (
CONFIGPATH = "./config/prod.yml"
// TODO read this params from config
GRPCP_PORT = "50077"
GATEWAY_PORT = "8080"
)
func loadConfig(path string) serving.Yaml {
data, err := ioutil.ReadFile(path)
if err != nil {
log.Fatalf("Can't reading config: %v", err)
}
m := make(serving.Yaml)
err = yaml.Unmarshal(data, &m)
if err != nil {
log.Fatalf("error: %v", err)
}
return m
}
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
config := loadConfig(CONFIGPATH)
addrGRPC := ":" + GRPCP_PORT
addrGateway := ":" + GATEWAY_PORT
errGateway := serving.Errch(func() error { return gateway.Start(ctx, addrGateway, addrGRPC) })
errGRPC := serving.Errch(func() error { return serving.Start(ctx, addrGRPC, config) })
select {
case reason := <-errGRPC:
log.Println("grpc server is down", "reason", reason)
cancel()
case reason := <-errGateway:
log.Println("gateway server is down", "reason", reason)
cancel()
case <-ctx.Done():
log.Println("context is canceled", "reason", ctx.Err())
}
// wait grpc and gateway
<-ctx.Done()
}