@@ -173,23 +173,21 @@ var (
173
173
)
174
174
175
175
func setValue (rv reflect.Value , str string ) error {
176
+ // Zero value
177
+ if str == "" {
178
+ rv .SetZero ()
179
+ return nil
180
+ }
181
+
176
182
switch rv .Kind () {
177
183
case reflect .Bool :
178
- // Zero value
179
- if str == "" {
180
- rv .SetZero ()
181
- }
182
184
// Bool
183
185
if v , err := strconv .ParseBool (str ); err != nil {
184
186
return httpresponse .ErrBadRequest .Withf ("invalid value for %s: %q" , rv .Type (), str )
185
187
} else {
186
188
rv .SetBool (v )
187
189
}
188
190
case reflect .Int , reflect .Int8 , reflect .Int16 , reflect .Int32 , reflect .Int64 :
189
- // Zero value
190
- if str == "" {
191
- rv .SetZero ()
192
- }
193
191
// Duration
194
192
if rv .Type () == durationType {
195
193
if v , err := time .ParseDuration (str ); err != nil {
@@ -205,21 +203,13 @@ func setValue(rv reflect.Value, str string) error {
205
203
rv .SetInt (v )
206
204
}
207
205
case reflect .Uint , reflect .Uint8 , reflect .Uint16 , reflect .Uint32 , reflect .Uint64 :
208
- // Zero value
209
- if str == "" {
210
- rv .SetZero ()
211
- }
212
206
// Uint
213
207
if v , err := strconv .ParseUint (str , 10 , 64 ); err != nil {
214
208
return httpresponse .ErrBadRequest .Withf ("invalid value for %s: %q" , rv .Type (), str )
215
209
} else {
216
210
rv .SetUint (v )
217
211
}
218
212
case reflect .Float32 , reflect .Float64 :
219
- // Zero value
220
- if str == "" {
221
- rv .SetZero ()
222
- }
223
213
// Float
224
214
if v , err := strconv .ParseFloat (str , 64 ); err != nil {
225
215
return httpresponse .ErrBadRequest .Withf ("invalid value for %s: %q" , rv .Type (), str )
@@ -229,8 +219,13 @@ func setValue(rv reflect.Value, str string) error {
229
219
case reflect .String :
230
220
// String
231
221
rv .SetString (str )
222
+ default :
223
+ // TODO URL and Datetime
224
+ return httpresponse .ErrBadRequest .Withf ("invalid value for %s: %q" , rv .Type (), str )
232
225
}
233
- return httpresponse .ErrBadRequest .Withf ("invalid value for %s: %q" , rv .Type (), str )
226
+
227
+ // Return success
228
+ return nil
234
229
}
235
230
236
231
func typeName (rt reflect.Type ) string {
0 commit comments