-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make url
and http_url
work with url.URL.
#1231
base: master
Are you sure you want to change the base?
Conversation
if stringer, ok := field.Interface().(fmt.Stringer); ok { | ||
s = stringer.String() | ||
} else { | ||
panic(fmt.Sprintf("Bad field type %T", field.Interface())) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if stringer, ok := field.Interface().(fmt.Stringer); ok { | |
s = stringer.String() | |
} else { | |
panic(fmt.Sprintf("Bad field type %T", field.Interface())) | |
} | |
if stringer, ok := field.Interface().(fmt.Stringer); !ok { | |
panic(fmt.Sprintf("Bad field type %T", field.Interface())) | |
} | |
s = stringer.String() | |
return false | ||
} | ||
url, err := url.Parse(s) | ||
if err != nil || url.Scheme == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if err != nil || url.Scheme == "" { | |
if err != nil { |
|
||
return true | ||
if url.Host == "" && url.Fragment == "" && url.Opaque == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if url.Host == "" && url.Fragment == "" && url.Opaque == "" { | |
if url.Scheme == "" || (url.Host == "" && url.Fragment == "" && url.Opaque == "") { |
I've added a few comments suggesting readability improvements. |
Fixes Or Enhances
This makes the
url
andhttp_url
validations work withurl.URL
or any newtype that implements theStringer
interface. I'm not familiar with the codebase so it's kind of a PoC PR to see if you think this can be useful.Make sure that you've checked the boxes below before you submit PR:
But they don't pass, if this is a feature we want and it's the right approach I can investigate deeper. I suspect the reflection magic isn't working as I expected.
@go-playground/validator-maintainers