-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathquery.go
More file actions
54 lines (41 loc) · 713 Bytes
/
query.go
File metadata and controls
54 lines (41 loc) · 713 Bytes
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
package room
import (
"github.com/WEG-Technology/room/store"
"github.com/google/go-querystring/query"
"net/url"
)
type Query struct {
v any
}
type IQuery interface {
String() string
}
func NewQuery(v any) IQuery {
switch v := v.(type) {
case store.IMap:
return IMapQuery{v}
default:
return IUrlQuery{v}
}
}
type IMapQuery struct {
v store.IMap
}
func (q IMapQuery) String() string {
v := url.Values{}
q.v.Each(func(key string, value any) {
v.Add(key, value.(string))
})
vEncoded := v.Encode()
return vEncoded
}
type IUrlQuery struct {
v any
}
func (q IUrlQuery) String() string {
urlValues, err := query.Values(q.v)
if err != nil {
return ""
}
return urlValues.Encode()
}