@@ -173,23 +173,21 @@ var (
173173)
174174
175175func setValue (rv reflect.Value , str string ) error {
176+ // Zero value
177+ if str == "" {
178+ rv .SetZero ()
179+ return nil
180+ }
181+
176182 switch rv .Kind () {
177183 case reflect .Bool :
178- // Zero value
179- if str == "" {
180- rv .SetZero ()
181- }
182184 // Bool
183185 if v , err := strconv .ParseBool (str ); err != nil {
184186 return httpresponse .ErrBadRequest .Withf ("invalid value for %s: %q" , rv .Type (), str )
185187 } else {
186188 rv .SetBool (v )
187189 }
188190 case reflect .Int , reflect .Int8 , reflect .Int16 , reflect .Int32 , reflect .Int64 :
189- // Zero value
190- if str == "" {
191- rv .SetZero ()
192- }
193191 // Duration
194192 if rv .Type () == durationType {
195193 if v , err := time .ParseDuration (str ); err != nil {
@@ -205,21 +203,13 @@ func setValue(rv reflect.Value, str string) error {
205203 rv .SetInt (v )
206204 }
207205 case reflect .Uint , reflect .Uint8 , reflect .Uint16 , reflect .Uint32 , reflect .Uint64 :
208- // Zero value
209- if str == "" {
210- rv .SetZero ()
211- }
212206 // Uint
213207 if v , err := strconv .ParseUint (str , 10 , 64 ); err != nil {
214208 return httpresponse .ErrBadRequest .Withf ("invalid value for %s: %q" , rv .Type (), str )
215209 } else {
216210 rv .SetUint (v )
217211 }
218212 case reflect .Float32 , reflect .Float64 :
219- // Zero value
220- if str == "" {
221- rv .SetZero ()
222- }
223213 // Float
224214 if v , err := strconv .ParseFloat (str , 64 ); err != nil {
225215 return httpresponse .ErrBadRequest .Withf ("invalid value for %s: %q" , rv .Type (), str )
@@ -229,8 +219,13 @@ func setValue(rv reflect.Value, str string) error {
229219 case reflect .String :
230220 // String
231221 rv .SetString (str )
222+ default :
223+ // TODO URL and Datetime
224+ return httpresponse .ErrBadRequest .Withf ("invalid value for %s: %q" , rv .Type (), str )
232225 }
233- return httpresponse .ErrBadRequest .Withf ("invalid value for %s: %q" , rv .Type (), str )
226+
227+ // Return success
228+ return nil
234229}
235230
236231func typeName (rt reflect.Type ) string {
0 commit comments