forked from envoyproxy/ratelimit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.go
39 lines (36 loc) · 1.33 KB
/
common.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
package common
import (
pb_struct "github.com/lyft/ratelimit/proto/envoy/api/v2/ratelimit"
pb "github.com/lyft/ratelimit/proto/envoy/service/ratelimit/v2"
pb_legacy "github.com/lyft/ratelimit/proto/ratelimit"
)
func NewRateLimitRequest(domain string, descriptors [][][2]string, hitsAddend uint32) *pb.RateLimitRequest {
request := &pb.RateLimitRequest{}
request.Domain = domain
for _, descriptor := range descriptors {
newDescriptor := &pb_struct.RateLimitDescriptor{}
for _, entry := range descriptor {
newDescriptor.Entries = append(
newDescriptor.Entries,
&pb_struct.RateLimitDescriptor_Entry{Key: entry[0], Value: entry[1]})
}
request.Descriptors = append(request.Descriptors, newDescriptor)
}
request.HitsAddend = hitsAddend
return request
}
func NewRateLimitRequestLegacy(domain string, descriptors [][][2]string, hitsAddend uint32) *pb_legacy.RateLimitRequest {
request := &pb_legacy.RateLimitRequest{}
request.Domain = domain
for _, descriptor := range descriptors {
newDescriptor := &pb_legacy.RateLimitDescriptor{}
for _, entry := range descriptor {
newDescriptor.Entries = append(
newDescriptor.Entries,
&pb_legacy.RateLimitDescriptor_Entry{Key: entry[0], Value: entry[1]})
}
request.Descriptors = append(request.Descriptors, newDescriptor)
}
request.HitsAddend = hitsAddend
return request
}