Skip to content

Instantly share code, notes, and snippets.

@jclem
Created November 19, 2024 17:11
Show Gist options
  • Save jclem/9fdd16fb5d2d8e610e0a6f3fd1eb28a0 to your computer and use it in GitHub Desktop.
Save jclem/9fdd16fb5d2d8e610e0a6f3fd1eb28a0 to your computer and use it in GitHub Desktop.
func (c Collection) Validate() error {
v := vld.New()
strlen := vld.StrLen(1, 64)
v.Validate(
[]string{"name"},
strlen(c.Name),
)
v.Validate(
[]string{"tags", "key"},
vld.MapKeys[string, string](strlen)(c.Tags),
)
v.Validate(
[]string{"tags", "value"},
vld.MapValues[string](strlen)(c.Tags),
)
if err := v.GetError(); err != nil {
return fmt.Errorf("validate collection: %w", err)
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment