-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (44 loc) · 1.03 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
package main
import (
"flag"
"fmt"
"net"
"github.com/golang/glog"
"google.golang.org/grpc"
"github.com/crypto-bank/go-orderbook/server"
"github.com/crypto-bank/proto/orderbook"
)
var (
port = flag.Int("port", 8139, "Service listening port")
dbPath = flag.String("db-path", "/tmp/orderbook", "Database path")
)
func main() {
// Parse command line flags
flag.Parse()
// Defer flushing logs at shutdown
defer glog.Flush()
// Create a new server
srv, err := server.New(*dbPath)
if err != nil {
glog.Fatal(err)
}
// Defer closing a server
defer func() {
if err := srv.Close(); err != nil {
glog.Fatal(err)
}
}()
// Start TCP listener
listener, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
if err != nil {
glog.Fatalf("failed to listen: %v", err)
}
// Create new gRPC server
grpcServer := grpc.NewServer()
// Register orderbook service server
orderbook.RegisterOrderBookServer(grpcServer, srv)
// Start serving gRPC service
if err := grpcServer.Serve(listener); err != nil {
glog.Fatal(err)
}
}