Documentation ¶
Overview ¶
Package validator provides functions for validating data using the Go Playground Validator. It allows you to validate structs and individual fields, providing error messages in case of validation failures.
The package relies on the go-playground/validator/v10 library for validation and go-playground/universal-translator for translating error messages to human readable text.
Example Usage:
package main import ( "fmt" "github.com/romankravchuk/nix/validator" ) type User struct { Username string `validate:"required,min=4,max=32"` Email string `validate:"required,email"` Age int `validate:"gte=18"` } func main() { user := User{ Username: "john_doe", Email: "john.doe@example.com", Age: 25, } v := validator.New() if isValid := v.Validate(user); !isValid { fmt.Println("Validation failed:", v.Errors()) } else { fmt.Println("Validation successful!") } }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Validator ¶ added in v0.0.8
type Validator struct {
// contains filtered or unexported fields
}
func (*Validator) Errors ¶ added in v0.0.8
Errors returns the validation errors as a map of field names to error messages.
func (*Validator) RegisterRules ¶ added in v0.0.8
RegisterRules registers the custom validation rules for the given 'data'
Click to show internal directories.
Click to hide internal directories.