-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
40 lines (32 loc) · 896 Bytes
/
util.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
package grpcs
import (
"net/url"
"strings"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/grpc-ecosystem/grpc-gateway/v2/utilities"
"google.golang.org/protobuf/proto"
)
// serviceFromMethod returns the service
// /service.Foo/Bar => service.Foo
func serviceFromMethod(m string) string {
if len(m) == 0 {
return m
}
return strings.Split(strings.Trim(m, "/"), "/")[0]
}
type DefaultQueryParser struct{}
// Parse populates "values" into "msg".
// A value is ignored if its key starts with one of the elements in "filter".
func (*DefaultQueryParser) Parse(msg proto.Message, values url.Values, filter *utilities.DoubleArray) error {
for key, v := range values {
if len(v) == 0 {
delete(values, key)
continue
}
if len(v) == 1 && v[0] == "" {
delete(values, key)
continue
}
}
return new(runtime.DefaultQueryParser).Parse(msg, values, filter)
}