-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
64 lines (52 loc) · 1.43 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
// Copyright 2017 Johan Brandhorst. All Rights Reserved.
// See LICENSE for licensing terms.
package main
import (
"context"
"net"
"time"
"github.com/gogo/protobuf/types"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/reflection"
pbGoGo "github.com/johanbrandhorst/gogoproto-experiments/gogo/server"
)
var logger *logrus.Logger
func init() {
logger = logrus.StandardLogger()
logrus.SetLevel(logrus.DebugLevel)
logrus.SetFormatter(&logrus.TextFormatter{
ForceColors: true,
FullTimestamp: true,
TimestampFormat: time.RFC3339Nano,
DisableSorting: true,
})
// Should only be done from init functions
grpclog.SetLoggerV2(grpclog.NewLoggerV2(logger.Out, logger.Out, logger.Out))
}
type gogoSrv struct{}
func (g gogoSrv) Empty(_ context.Context, _ *types.Empty) (*pbGoGo.TestReply, error) {
t := time.Now()
return &pbGoGo.TestReply{
RequestTime: &t,
}, nil
}
func (g gogoSrv) TestMethod(_ context.Context, _ *pbGoGo.TestRequest) (*pbGoGo.TestReply, error) {
t := time.Now()
return &pbGoGo.TestReply{
RequestTime: &t,
}, nil
}
func main() {
gs := grpc.NewServer()
pbGoGo.RegisterTestServiceServer(gs, &gogoSrv{})
reflection.Register(gs)
addr := "localhost:10000"
l, err := net.Listen("tcp", addr)
if err != nil {
logger.WithError(err).Fatal("Failed to start listener")
}
logger.Info("Serving on https://" + addr)
logger.Fatal(gs.Serve(l))
}