Iterate & test your go-playground/validator
struct tags
Go to the app!
This is a simple web app that allows you to test your go-playground/validator
struct tags. You can use it at https://apps.abhijithota.me/go-validator-playground.
go-playground/validator
is probably the most popular Go validation library. It uses (or exploits, dare I say) struct tags to validate the particular struct fields.
It's pretty flexible, but it's also a PITA when you misspell something or forget the syntax. This tool is not a silver bullet but it is here to help you find out what's wrong with the code more quickly.
It uses WebAssembly to run the go-playground/validator
library in the browser.
- User enters the struct type definition.
- User enters the corresponding JSON data.
- These two (
string
) values are passed to the WebAssembly module. - The struct definition is parsed and the struct type is created dynamically using some
reflect
magic. - The JSON is unmarshalled into the struct.
- The actual validation is performed.
- Errors and invalid fields/tags are returned back to the JS code.
- Tests
- Add highlights in the
textarea
for invalid fields/tags - Syntax highlighting maybe?
- Minimum responsiveness
- Write blog post — "A primer on Go reflection"
- Maybe buy a domain if enough people use it
I mostly coded this as a way to explore WebAssembly and out of frustration with not knowing the unpredictable behaviour of struct tags.
It is mostly a proof of concept. I've tested in as much as possible manually but it might still fail, in which case, please reload the page and try again.
Thanks to https://gotemplate.io/ for the inspiration.