Created
June 29, 2021 14:15
-
-
Save Siva-Karthi/0ab53dc193d924269a1448797365b10f to your computer and use it in GitHub Desktop.
simple go validator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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