-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (38 loc) · 880 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
42
43
44
45
46
package main
import (
"log"
"net"
"github.com/thetommytwitch/simple-cache-service/backends/memory"
"github.com/thetommytwitch/simple-cache-service/config"
pb "github.com/thetommytwitch/simple-cache-service/proto/go"
"google.golang.org/grpc"
)
const (
port = ":7771"
)
var server pb.CacheServer
func init() {
c, err := config.Get()
if err != nil {
panic(err)
}
switch c.Backend {
case "memory":
server = memory.NewServer()
default:
panic("backend not set there is a problem with the config")
}
}
func main() {
lis, err := net.Listen("tcp", port)
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
var opts []grpc.ServerOption
grpcServer := grpc.NewServer(opts...)
log.Printf("listening on: %s", port)
pb.RegisterCacheServer(grpcServer, server)
if err := grpcServer.Serve(lis); err != nil {
log.Fatalf("failed to serve: %v", err)
}
}