-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.go
30 lines (23 loc) · 772 Bytes
/
utils.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
package genratelimit
import (
"fmt"
"strings"
gendoc "github.com/pseudomuto/protoc-gen-doc"
)
func getDefaultMethodPath(service *gendoc.Service, method *gendoc.ServiceMethod) string {
return fmt.Sprintf("/%s/%s", service.FullName, method.Name)
}
func formatKey(key, bucketName string, count int) (string, error) {
updatedKey := key
keys := strings.Count(key, delimiter)
if keys == count && (string(key[len(key)-1]) != delimiter && bucketName != "") {
return "", fmt.Errorf("key %s has too tuples, last one should be reserved for bucket", key)
}
if keys > count-1 {
return "", fmt.Errorf("key %s has too many delimiters", key)
}
for i := 0; i < (count - keys - 1); i++ {
updatedKey = updatedKey + delimiter
}
return updatedKey + bucketName, nil
}