-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
55 lines (47 loc) · 1.4 KB
/
client.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
package main
import (
"fmt"
"grpc-wrapper-framework/atreus"
"grpc-wrapper-framework/config"
pb "grpc-wrapper-framework/proto"
"golang.org/x/net/context"
//"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
)
func extractIncomingAndClone(ctx context.Context) metadata.MD {
md, ok := metadata.FromOutgoingContext(ctx)
if !ok {
return metadata.MD{}
}
return md.Copy()
}
func main() {
var (
md metadata.MD // == nil
fail int
)
config.InitConfigAbsolutePath("../conf", "grpc_client", "yaml")
config.AtreusCliConfigInit()
conn, _ := atreus.NewClient(config.GetAtreusCliConfig())
md = metadata.MD{}
md["sendParamA"] = nil
client := pb.NewGreeterServiceClient(conn.RpcPersistClient)
//add request
ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(atreus.DefaultAtreusReqIDKey, "cvalue", "app", "test", "token", "test", "method", "normal", "key2", "value2"))
cloneMd := extractIncomingAndClone(ctx)
cloneMd.Set("key4", "value4")
ctx = metadata.NewOutgoingContext(ctx, cloneMd)
fromOut, _ := metadata.FromOutgoingContext(ctx)
fmt.Println("metadata.FromOutgoingContext(ctx)=", fromOut)
for i := 0; i < 1; i++ {
msg := fmt.Sprintf("hello golang:%d", i)
resp, err := client.SayHello(ctx, &pb.HelloRequest{Name: msg})
if err != nil {
fmt.Println(err)
fail++
} else {
fmt.Printf("normal hello: resp=%v, error=%v\n", resp, err)
}
}
fmt.Println(fail)
}