Ecosyste.ms: Packages

An open API service providing package, version and dependency metadata of many open source software ecosystems and registries.

Top 4.3% on proxy.golang.org
Top 0.6% forks on proxy.golang.org

proxy.golang.org : gopkg.in/go-playground/validator.v1

Package validator implements value validations for structs and individual fields based on tags. The package contains a built in Validator instance for use, but you may also create a new instance if needed. A simple example usage: The error can be used like so Both StructValidationErrors and FieldValidationError implement the Error interface but it's intended use is for development + debugging, not a production error message. Why not a better error message? because this library intends for you to handle your own error messages Why should I handle my own errors? Many reasons, for me building an internationalized application I needed to know the field and what validation failed so that I could provide an error in the users specific language. The hierarchical structure is hard to work with sometimes.. Agreed Flatten function to the rescue! Flatten will return a map of FieldValidationError's but the field name will be namespaced. Custom functions can be added A custom tag name can be set to avoid conficts, or just have a shorter name Multiple validators on a field will process in the order defined Bad Validator definitions are not handled by the library Here is a list of the current built in validators: Validator notes: This package panics when bad input is provided, this is by design, bad code like that should not make it to production.

Registry - Source - Documentation - JSON
purl: pkg:golang/gopkg.in/go-playground/validator.v1
Keywords: error-handling, translation, validation
License: MIT
Latest release: 21 days ago
Namespace: gopkg.in/go-playground
Stars: 12,682 on GitHub
Forks: 1,154 on GitHub
See more repository details: repos.ecosyste.ms
Last synced: 10 minutes ago