Skip to content

Instantly share code, notes, and snippets.

@whiler
Created March 4, 2024 00:45
Show Gist options
  • Save whiler/4f436195d39a08ac5ab2ad75887f57ee to your computer and use it in GitHub Desktop.
Save whiler/4f436195d39a08ac5ab2ad75887f57ee to your computer and use it in GitHub Desktop.
golang validator simple usage
import "github.com/go-playground/validator/v10"
type Base struct {
Name string `yaml:"name" validate:"required"`
}
type Ext struct {
ID int `yaml:"id" validate:"gte=1,lt=10"`
}
type The struct {
Ext *Ext `yaml:",inline"`
Base *Base `yaml:"base"`
Children []*Base `yaml:"children" validate:"unique=Name,dive"`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment