Skip to content

Instantly share code, notes, and snippets.

@Siva-Karthi
Created June 29, 2021 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Siva-Karthi/0ab53dc193d924269a1448797365b10f to your computer and use it in GitHub Desktop.
Save Siva-Karthi/0ab53dc193d924269a1448797365b10f to your computer and use it in GitHub Desktop.
simple go validator
package main
import (
"fmt"
"github.com/go-playground/validator"
)
type Student struct {
Name string `validate:"required"`
}
func main() {
bob := &Student{
}
appValidator := validator.New()
err := appValidator.Struct(bob)
if err != nil{
validationErrors := err.(validator.ValidationErrors)
fmt.Println("validationErrors",validationErrors)
}
print("done")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment