# README
go-validation
Simple and flexible Go (Golang) validation library.
This library provides an elegant DSL for defining validation constraints in Go.
Installation
Pull in the library using go get
:
$ go get github.com/seeruk/go-validation
License
MIT
# Packages
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Functions
ConstraintViolationsToProto converts a slice of ConstraintViolations into a slice of the ProtoBuf representation of those ConstraintViolations, making them ready to use for example in a gRPC service in a similar way to how ConstraintViolation can already be used in JSON web services.
CreateValidateFunc allows the caller to create a customised validate function, using the given option(s), allowing them to avoid manually creating a context and using the simpler API while maintaining the ability to customise the validation context.
FieldName returns the output name for a field of the given field name.
IsEmpty checks if a value is "empty".
IsNillable returns true if the given value is of a nillable type.
LazyDynamic is a Constraint that's extremely similar to Lazy, and fulfils mostly the same purpose, but instead expects a function that has a single argument of the type being validated.
MustBe will panic if the given reflect.Value is not one of the given reflect.Kind kinds.
NewContext returns a new Context, with a Value created for the given any value.
ShouldBe is the non-panicking alternative to MustBe.
UnwrapType takes the given reflect.Type, and if it's a pointer gets the pointer element's type.
UnwrapValue takes the given reflect.Value, and if it's a pointer gets the pointer element.
Validate executes the given constraint(s) against the given value, returning any violations of those constraints.
ValidateContext is exactly like Validate, except it doesn't create a Context for you.
ViolationsFromStatus returns the constraint violations from the given gRPC status.
ViolationsToStatus returns the given set of constraint violations as a gRPC status.
When conditionally runs some constraints.
WhenFn lazily conditionally runs some constraints.
# Constants
DefaultNameStructTag is the default struct tag used to override the name of struct fields in the path that's output.
All possible PathKind values.
All possible PathKind values.
# Structs
ConstraintViolation contains information to highlight a value failing to fulfil the requirements of a Constraint.
Context contains useful information for a Constraint, including the value(s) being validated.
Value represents a value to be validated, and it's "name" (i.e.
# Interfaces
Constraint represents a type that will validate a value and/or adjust the validation scope for further validation (e.g.
# Type aliases
ConstraintFunc provides a convenient way of defining a Constraint as a function instead of a struct, keeping code more compact.
Constraints is simply a collection of many constraints.
Elements is a Constraint used to validate every value (element) in an array, a map, or a slice.
Fields is a Constraint used to validate the values of specific fields on a struct.
Keys is a Constraint used to validate the keys of a map.
Lazy is a Constraint that allows a function that returns Constraints to be evaluated at validation-time.
Map is a Constraint used to validate a map.
PathKind enumerates the different possible kinds of values that we validate.