...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package client
19
20 import (
21 "net/url"
22 "reflect"
23
24 "github.com/google/go-querystring/query"
25 )
26
27
28 type ListOpts struct {
29
30 Offset int `url:"offset"`
31
32 Limit int `url:"limit"`
33
34 Cached *bool `url:"cached,omitempty"`
35
36 StoragePool []string `url:"storage_pools"`
37 Resource []string `url:"resources"`
38 Node []string `url:"nodes"`
39 Prop []string `url:"props"`
40 Snapshots []string `url:"snapshots"`
41 Status string `url:"status,omitempty"`
42
43
44 Content bool `url:"content,omitempty"`
45 }
46
47 func genOptions(opts ...*ListOpts) *ListOpts {
48 if opts == nil || len(opts) == 0 {
49 return nil
50 }
51
52 return opts[0]
53 }
54
55 func addOptions(s string, opt interface{}) (string, error) {
56 v := reflect.ValueOf(opt)
57 if v.Kind() == reflect.Ptr && v.IsNil() {
58 return s, nil
59 }
60
61 u, err := url.Parse(s)
62 if err != nil {
63 return s, err
64 }
65
66 vs, err := query.Values(opt)
67 if err != nil {
68 return s, err
69 }
70
71 u.RawQuery = vs.Encode()
72 return u.String(), nil
73 }
74
View as plain text