Skip to content
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

Merged
merged 9 commits into from
Jul 12, 2017
Merged

Conversation

bigblind
Copy link
Contributor

@bigblind bigblind commented Jul 8, 2017

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.

@bigblind
Copy link
Contributor Author

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.

@urakozz
Copy link
Owner

urakozz commented Jul 10, 2017

@bigblind could you please add it to the .gitignore and remove?

@bigblind
Copy link
Contributor Author

bigblind commented Jul 10, 2017 via email

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)
Copy link
Contributor

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) ...

Copy link
Contributor Author

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.

Copy link
Owner

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@yurykozyrev
Copy link
Contributor

@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.
@urakozz urakozz merged commit 02eb70d into urakozz:master Jul 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants