File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -168,7 +168,7 @@ func newMetaField(rf reflect.StructField) (*Meta, error) {
168168
169169var (
170170 timeType = reflect .TypeOf (time.Time {})
171- urlType = reflect .TypeOf ((* url .URL )(nil )). Elem ()
171+ urlType = reflect .TypeOf ((* url .URL )(nil ))
172172 durationType = reflect .TypeOf (time .Duration (0 ))
173173)
174174
@@ -219,8 +219,16 @@ func setValue(rv reflect.Value, str string) error {
219219 case reflect .String :
220220 // String
221221 rv .SetString (str )
222+ case reflect .Ptr :
223+ if rv .Type () == urlType {
224+ if v , err := url .Parse (str ); err == nil {
225+ rv .Set (reflect .ValueOf (v ))
226+ return nil
227+ }
228+ }
229+ fallthrough
222230 default :
223- // TODO URL and Datetime
231+ // TODO: Datetime
224232 return httpresponse .ErrBadRequest .Withf ("invalid value for %s: %q" , rv .Type (), str )
225233 }
226234
@@ -254,10 +262,11 @@ func typeName(rt reflect.Type) string {
254262 if subtype := typeName (rt .Elem ()); subtype != "" && rt .Key ().Kind () == reflect .String {
255263 return "map(" + subtype + ")"
256264 }
257- case reflect .Struct :
265+ case reflect .Ptr :
258266 if rt == urlType {
259267 return "url"
260268 }
269+ case reflect .Struct :
261270 if rt == timeType {
262271 return "datetime"
263272 }
You can’t perform that action at this time.
0 commit comments