forked from beatlabs/patron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
74 lines (61 loc) · 1.7 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
65
66
67
68
69
70
71
72
73
74
package main
import (
"context"
"fmt"
"os"
"github.com/beatlabs/patron"
"github.com/beatlabs/patron/component/grpc"
"github.com/beatlabs/patron/component/grpc/greeter"
"github.com/beatlabs/patron/log"
)
const (
awsRegion = "eu-west-1"
awsID = "test"
awsSecret = "test"
awsToken = "token"
awsSQSEndpoint = "http://localhost:4576"
awsSQSQueue = "patron"
)
func init() {
err := os.Setenv("PATRON_LOG_LEVEL", "debug")
if err != nil {
fmt.Printf("failed to set log level env var: %v", err)
os.Exit(1)
}
err = os.Setenv("PATRON_JAEGER_SAMPLER_PARAM", "1.0")
if err != nil {
fmt.Printf("failed to set sampler env vars: %v", err)
os.Exit(1)
}
err = os.Setenv("PATRON_HTTP_DEFAULT_PORT", "50005")
if err != nil {
fmt.Printf("failed to set default patron port env vars: %v", err)
os.Exit(1)
}
}
type greeterServer struct {
greeter.UnimplementedGreeterServer
}
func (gs *greeterServer) SayHello(ctx context.Context, req *greeter.HelloRequest) (*greeter.HelloReply, error) {
log.FromContext(ctx).Infof("request received: %v", req.String())
return &greeter.HelloReply{Message: fmt.Sprintf("Hello, %s %s!", req.GetFirstname(), req.GetLastname())}, nil
}
func main() {
name := "sixth"
version := "1.0.0"
err := patron.SetupLogging(name, version)
if err != nil {
fmt.Printf("failed to set up logging: %v", err)
os.Exit(1)
}
cmp, err := grpc.New(50006).Create()
if err != nil {
log.Fatalf("failed to create gRPC component: %v", err)
}
greeter.RegisterGreeterServer(cmp.Server(), &greeterServer{})
ctx := context.Background()
err = patron.New(name, version).WithComponents(cmp).Run(ctx)
if err != nil {
log.Fatalf("failed to create and run service: %v", err)
}
}