-
Notifications
You must be signed in to change notification settings - Fork 10
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
implement a bunch of validation keywords #1
Conversation
Whoops, that workspace stuff wasn't meant to be in there. Gogland, the IDE I use, adds it, and I usually add it to my .gitignore so it doens't get into git. |
@bigblind could you please add it to the .gitignore and remove? |
That's the plan, will do asap.
…On Mon, Jul 10, 2017 at 2:40 PM Yury Kozyrev ***@***.***> wrote:
@bigblind <https://github.com/bigblind> could you please add it to the
.gitignore and remove?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAtA1dG7c4wfTuzQjQJQihuKLoq_ZcLtks5sMhurgaJpZM4ORqxD>
.
|
generator.go
Outdated
|
||
// Some helper functions for not having to create temp variables all over the place | ||
func int64ptr(i interface{}) *int64 { | ||
j := reflect.ValueOf(i).Convert(reflect.TypeOf(int64(0))).Interface().(int64) |
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.
Please create common variables the beginning of the file for reflect types (int64, float64)
var rTypeInt64, rTypeFloat64 = reflect.TypeOf(int64(0)), reflect.TypeOf(float64(0))
Then in this method please first check if given interface is convertible to the destination you want, like if value.Type().ConvertibleTo(rTypeInt64) ...
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.
What would you want me to do if the interface is not convertible? Just panic? The generator currently doesn't have a mechanism for returning errors, and in order to add that, I'd have to change the signature of every method so that it can return an error.
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.
ignore and return nil.
generator.go
Outdated
} | ||
|
||
func float64ptr(i interface{}) *float64 { | ||
j := reflect.ValueOf(i).Convert(reflect.TypeOf(float64(0))).Interface().(float64) |
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.
same here
@bigblind I added some comments please check. After those fixes let's merge it |
These functions now use global variables to store the reflect.Types they need, and check whether the values they are given can be converted to the type in the function name.
I implemented a bunch of validators from the spec. Mostly object validators, which are hard to define inside tags, and array validators, some of which I might still ad, are still missing.