/
main.go
78 lines (67 loc) · 1.58 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
75
76
77
78
package main
import (
"log"
"os"
"code.cloudfoundry.org/go-loggregator/rpc/loggregator_v2"
"code.cloudfoundry.org/loggregator-release/src/plumbing"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
func main() {
dopplerAddr := os.Getenv("DOPPLER_ADDR")
shardID := os.Getenv("SHARD_ID")
caPath := os.Getenv("CA_PATH")
certPath := os.Getenv("CERT_PATH")
keyPath := os.Getenv("KEY_PATH")
var missing []string
if dopplerAddr == "" {
missing = append(missing, "DOPPLER_ADDR")
}
if shardID == "" {
missing = append(missing, "SHARD_ID")
}
if caPath == "" {
missing = append(missing, "CA_PATH")
}
if certPath == "" {
missing = append(missing, "CERT_PATH")
}
if keyPath == "" {
missing = append(missing, "KEY_PATH")
}
if len(missing) > 0 {
log.Fatalf("missing required environment variables: %v", missing)
}
creds, err := plumbing.NewClientCredentials(
certPath,
keyPath,
caPath,
"doppler",
)
if err != nil {
log.Fatalf("failed to load client credentials: %s", err)
}
conn, err := grpc.Dial(dopplerAddr, grpc.WithTransportCredentials(creds))
if err != nil {
log.Fatalf("failed to dial doppler: %s", err)
}
client := loggregator_v2.NewEgressClient(conn)
stream, err := client.BatchedReceiver(
context.Background(),
&loggregator_v2.EgressBatchRequest{
ShardId: shardID,
},
)
if err != nil {
log.Fatalf("failed to open stream from doppler V2: %s", err)
}
for {
batch, err := stream.Recv()
if err != nil {
log.Fatalf("failed to read from stream: %s", err)
}
for _, e := range batch.GetBatch() {
log.Printf("%+v", e)
}
}
}