Valy
Valy is a struct validator for golang.
Install / Use
/learn @cpapidas/ValyREADME
Valy Validator
Valy is a struct validator manager that helps you to validate the fields according to the predefined properties. It can validate any struct and return the errors as types of map[string]string or JSON. Valy fully supports custom errors per field.
Installation
go get github.com/cpapidas/valy
Usage
Simple Example
type user struct {
Username string `validate:"required=true,min=10,max=23"`
Password string `validate:"required=true,err=password is required"`
Age int `validate:"required=true,min=10,max=23"`
}
u := user{
Username: "cpapidas",
Age: 9,
}
validationErrs, err := valy.Validate(u)
if err != nil {
fmt.Println(err)
}
if validationErrs != nil {
fmt.Println(validationErrs)
}
JSON Example
type user struct {
Username string `json:"username" validate:"required=true,min=10,max=23"`
Password string `json:"password" validate:"required=true,err=password is required"`
Age int `validate:"required=true,min=10,max=23"`
}
u := user{
Username: "cpapidas",
Age: 3,
}
validationErrs, err := valy.JValidate(u)
if err != nil {
fmt.Println(err)
}
if validationErrs != nil {
// return the json object to the client
fmt.Println("Validation errors", string(validationErrs))
}
Custom Errors Example
type user struct {
Username string `json:"username" validate:"required=true,min=10,max=23"`
Password string `json:"password" validate:"required=true,err=password is required"`
Age int `validate:"required=true,min=10,max=23"`
}
u := user{
Username: "cpapidas",
Age: 11,
}
errMess := map[string]string{
"Username": "Username is required and should contain between 10 and 23 characters.",
}
validationErrs, err := valy.Validate(u, errMess)
if err != nil {
fmt.Println(err)
}
if validationErrs != nil {
fmt.Println(validationErrs)
}
Supported Validators
string
type user struct {
Field1 string `validate:"required=true"`
Field2 string `validate:"min=10"`
Field3 string `validate:"max=23"`
Field4 string `validate:"max=23,err=Just a custom error"`
}
numeric
type user struct {
Field1 int `validate:"required=true"`
Field2 float32 `validate:"min=10"`
Field3 uint `validate:"max=23"`
Field4 unit8 `validate:"max=23,err=Just a custom error"`
}
Related Skills
node-connect
353.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
xurl
353.1kA CLI tool for making authenticated requests to the X (Twitter) API. Use this skill when you need to post tweets, reply, quote, search, read posts, manage followers, send DMs, upload media, or interact with any X API v2 endpoint.
frontend-design
111.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
353.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
