/
grpc.go
67 lines (51 loc) 路 1.15 KB
/
grpc.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
package model
import "google.golang.org/grpc/metadata"
type TriggerType string
const TriggerTypeGRPC TriggerType = "grpc"
type GRPCHeader struct {
Key string `expr_enabled:"true"`
Value string `expr_enabled:"true"`
}
type GRPCRequest struct {
ProtobufFile string `expr_enabled:"true"`
Address string `expr_enabled:"true"`
Service string `expr_enabled:"true"`
Method string `expr_enabled:"true"`
Request string `expr_enabled:"true"`
Metadata []GRPCHeader
Auth *HTTPAuthenticator
}
func (a GRPCRequest) Headers() []string {
h := []string{}
for _, md := range a.Metadata {
// ignore invalid values
if md.Key == "" {
continue
}
h = append(h, md.Key+": "+md.Value)
}
return h
}
func (a GRPCRequest) MD() *metadata.MD {
md := metadata.MD{}
for _, header := range a.Metadata {
// ignore invalid values
if header.Key == "" {
continue
}
md[header.Key] = []string{header.Value}
}
return &md
}
func (a GRPCRequest) Authenticate() {
if a.Auth == nil {
return
}
a.Auth.AuthenticateGRPC()
}
type GRPCResponse struct {
Status string
StatusCode int
Metadata []GRPCHeader
Body string
}