Values returns the url.Values encoding of v. Values expects to be passed a struct, and traverses it recursively using the following encoding rules. Each exported struct field is encoded as a URL parameter unless - the field's tag is "-", or - the field is empty and its tag specifies the "omitempt
(v interface{})
| 123 | // Multiple fields that encode to the same URL parameter name will be included |
| 124 | // as multiple URL values of the same name. |
| 125 | func Values(v interface{}) (url.Values, error) { |
| 126 | values := make(url.Values) |
| 127 | |
| 128 | if v == nil { |
| 129 | return values, nil |
| 130 | } |
| 131 | |
| 132 | val := reflect.ValueOf(v) |
| 133 | for val.Kind() == reflect.Ptr { |
| 134 | if val.IsNil() { |
| 135 | return values, nil |
| 136 | } |
| 137 | val = val.Elem() |
| 138 | } |
| 139 | |
| 140 | if val.Kind() != reflect.Struct { |
| 141 | return nil, fmt.Errorf("query: Values() expects struct input. Got %v", val.Kind()) |
| 142 | } |
| 143 | |
| 144 | err := reflectValue(values, val, "") |
| 145 | return values, err |
| 146 | } |
| 147 | |
| 148 | // reflectValue populates the values parameter from the struct fields in val. |
| 149 | // Embedded structs are followed recursively (using the rules defined in the |
searching dependent graphs…