-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (39 loc) · 1.01 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
package main
import (
"context"
"flag"
"fmt"
"log"
"net"
"net/http"
"github.com/brotherlogic/mdb/server"
"github.com/prometheus/client_golang/prometheus/promhttp"
"google.golang.org/grpc"
pb "github.com/brotherlogic/mdb/proto"
)
var (
port = flag.Int("port", 8080, "Server port for grpc traffic")
metricsPort = flag.Int("metrics_port", 8081, "Metrics port")
)
func main() {
flag.Parse()
ctx := context.Background()
s := server.NewServer(ctx)
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
if err != nil {
log.Fatalf("mdb is actually unable to listen on the grpc port %v: %v", *port, err)
}
gs := grpc.NewServer()
pb.RegisterMDBServiceServer(gs, s)
http.Handle("/metrics", promhttp.Handler())
go func() {
err := http.ListenAndServe(fmt.Sprintf(":%v", *metricsPort), nil)
log.Fatalf("mdb is unable to serve metrics: %v", err)
}()
// Background run the refill loop
go func() {
s.RunRefillLoop()
}()
err = gs.Serve(lis)
log.Printf("mdb is unable to serve http: %v", err)
}