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

Public types #44

Closed
mkrull opened this issue Jan 5, 2015 · 7 comments
Closed

Public types #44

mkrull opened this issue Jan 5, 2015 · 7 comments

Comments

@mkrull
Copy link

mkrull commented Jan 5, 2015

Do you plan on making types and interfaces like jsonLoader public (like it was with for example JsonSchemaDocument before)?
That would simplify definition of types/structs that have loaders as members or function paramerters.

If not could you suggest an alternative to achive the same without losing type safety to interface{}?

@xeipuuv
Copy link
Owner

xeipuuv commented Jan 5, 2015

I can make the interface jsonLoader public, does that solve your issue ?

@mkrull
Copy link
Author

mkrull commented Jan 5, 2015

I am currently using gojsonschema to validate input for a web application and I would like to avoid to reload the schema for every request from disk. With the pre-christmas version I could just load the schemas once and put them into a map for use by the requests.

I guess I can use the jsonGoLoader to at least avoid file io for every request. So having JsonLoader public should solve the issue for me, let me try things first and I let you know.

@xeipuuv
Copy link
Owner

xeipuuv commented Jan 5, 2015

Maybe that is what you are looking for ? https://github.com/xeipuuv/gojsonschema/blob/master/README.md#validation

@mkrull
Copy link
Author

mkrull commented Jan 5, 2015

Yes, and if JsonLoader is public I can do things like

schemas := make(map[string]gojsonschema.JsonLoader)
schemas["someschema"] = gojsonschema.NewGoLoader(someObjectUnmarshaledFromFile)

and use the loader from the map later when validating my data. To create that map or any type with JsonLoader as member it has to be public. But I am open for different ideas if you want to keep it private. But making it public should not hurt because I guess the private loaders will always implement the JsonLoader interface anyway, right?

@xeipuuv
Copy link
Owner

xeipuuv commented Jan 5, 2015

This works, alternatively you can create a map of gojsonschema.Schema ( public ),
this is up to you.

Now you are right, i guess it makes sense to have the JSONLoader interface made public.

sigu-399 added a commit that referenced this issue Jan 5, 2015
interface made public
@mkrull
Copy link
Author

mkrull commented Jan 5, 2015

Oh right, for my example a map of schemas would be more convenient.

A public Loader interface could also enable more fancy loaders like fetching from databases over non http interfaces (e.g. protobuffer interface of riak) and things like that, that do not need to be built in but could come in handy in specific use cases.

@xeipuuv
Copy link
Owner

xeipuuv commented Jan 5, 2015

I agree

@xeipuuv xeipuuv closed this as completed Jan 5, 2015
binary132 pushed a commit to binary132/gojsonschema that referenced this issue Jan 27, 2015
interface made public
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

No branches or pull requests

2 participants