https://github.com/tiaguinho/required
Validate value of field
https://github.com/tiaguinho/required
go golang required requiredvalidator validation
Last synced: 8 months ago
JSON representation
Validate value of field
- Host: GitHub
- URL: https://github.com/tiaguinho/required
- Owner: tiaguinho
- License: mit
- Created: 2017-05-19T17:46:24.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-12T06:58:27.000Z (over 7 years ago)
- Last Synced: 2024-06-20T02:08:34.461Z (over 1 year ago)
- Topics: go, golang, required, requiredvalidator, validation
- Language: Go
- Homepage:
- Size: 11.7 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Required [](https://travis-ci.org/tiaguinho/required) [](https://godoc.org/github.com/tiaguinho/required) [](https://goreportcard.com/report/github.com/tiaguinho/required) [](https://codecov.io/gh/tiaguinho/required)
Required is used to validate if the field value is empty### Install
```bash
go get github.com/tiaguinho/required
```### Example
Simplest way to use the package:
```go
package mainimport (
"github.com/tiaguinho/required"
"log"
)type Test struct {
FirstName string `json:"first_name" required:"-"`
LastName string `json:"last_name" required:"last name is required"`
}func main() {
t := Test{
FirstName: "Go",
LastName: "Required",
}
if err := required.Validate(t); err != nil {
log.Println(err)
}
}
```If you like to get all the validation messages with field's name to return in some API, just change to this:
```go
func main() {
t := Test{
FirstName: "Go",
LastName: "Required",
}
if msg, err := required.ValidateWithMessage(t); err != nil {
log.Println(err, msg)
}
}
```