-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
49 lines (38 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
package main
import (
"flag"
"fmt"
"log"
"net"
"github.com/aau-network-security/haaukins-exercises/server"
pb "github.com/aau-network-security/haaukins-exercises/proto"
)
const (
defaultConfigFile = "config.yml"
)
func main() {
confFilePtr := flag.String("config", defaultConfigFile, "configuration file")
flag.Parse()
c, err := server.NewConfigFromFile(*confFilePtr)
if err != nil {
log.Fatalf("unable to read configuration file [%s]: %s", *confFilePtr, err)
}
s, err := server.NewServer(c)
if err != nil {
log.Fatal(err)
}
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", c.Port))
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
opts, err := s.GrpcOpts(c)
if err != nil {
log.Fatalf("failed to retrieve server options %s", err.Error())
}
gRPCServer := s.NewGRPCServer(opts...)
pb.RegisterExerciseStoreServer(gRPCServer, s)
log.Printf("INFO server waiting for clients on port %d", c.Port)
if err := gRPCServer.Serve(lis); err != nil {
log.Fatalf("failed to serve: %v", err)
}
}