forked from beatlabs/patron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (49 loc) · 1.46 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
package main
import (
"context"
"fmt"
"os"
"github.com/beatlabs/patron"
"github.com/beatlabs/patron/component/grpc"
"github.com/beatlabs/patron/examples"
"github.com/beatlabs/patron/log"
)
func init() {
err := os.Setenv("PATRON_LOG_LEVEL", "debug")
if err != nil {
log.Fatalf("failed to set log level env var: %v", err)
}
err = os.Setenv("PATRON_JAEGER_SAMPLER_PARAM", "1.0")
if err != nil {
log.Fatalf("failed to set sampler env vars: %v", err)
}
err = os.Setenv("PATRON_HTTP_DEFAULT_PORT", "50005")
if err != nil {
log.Fatalf("failed to set default patron port env vars: %v", err)
}
}
type greeterServer struct {
examples.UnimplementedGreeterServer
}
func (gs *greeterServer) SayHello(ctx context.Context, req *examples.HelloRequest) (*examples.HelloReply, error) {
log.FromContext(ctx).Infof("request received: %v", req.String())
return &examples.HelloReply{Message: fmt.Sprintf("Hello, %s %s!", req.GetFirstname(), req.GetLastname())}, nil
}
func main() {
name := "grpc"
version := "1.0.0"
service, err := patron.New(name, version, patron.TextLogger())
if err != nil {
log.Fatalf("failed to set up service: %v", err)
}
cmp, err := grpc.New(50006).Create()
if err != nil {
log.Fatalf("failed to create gRPC component: %v", err)
}
examples.RegisterGreeterServer(cmp.Server(), &greeterServer{})
ctx := context.Background()
err = service.WithComponents(cmp).Run(ctx)
if err != nil {
log.Fatalf("failed to create and run service: %v", err)
}
}