https://github.com/core-go/validator
https://github.com/core-go/validator
data-validation validate validation validator
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/core-go/validator
- Owner: core-go
- Created: 2020-06-24T08:25:40.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-10-31T03:25:41.000Z (over 3 years ago)
- Last Synced: 2025-01-10T04:15:08.615Z (6 months ago)
- Topics: data-validation, validate, validation, validator
- Language: Go
- Homepage:
- Size: 21.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Validator
- ErrorMessage
- Validator
- DefaultValidator## Installation
Please make sure to initialize a Go module before installing core-go/validator:
```shell
go get -u github.com/core-go/validator
```Import:
```go
import "github.com/core-go/validator"
```## Details:
#### error_message.go
```go
type ErrorMessage struct {
Field string `mapstructure:"field" json:"field,omitempty" gorm:"column:field" bson:"field,omitempty" dynamodbav:"field,omitempty" firestore:"field,omitempty"`
Code string `mapstructure:"code" json:"code,omitempty" gorm:"column:code" bson:"code,omitempty" dynamodbav:"code,omitempty" firestore:"code,omitempty"`
Param string `mapstructure:"param" json:"param,omitempty" gorm:"column:param" bson:"param,omitempty" dynamodbav:"param,omitempty" firestore:"param,omitempty"`
Message string `mapstructure:"message" json:"message,omitempty" gorm:"column:message" bson:"message,omitempty" dynamodbav:"message,omitempty" firestore:"message,omitempty"`
}
```#### validator.go
```go
type Validator interface {
Validate(ctx context.Context, model interface{}) ([]ErrorMessage, error)
}
```## Example:
```go
package mainimport (
"context"
"fmt"
"github.com/core-go/validator"
"github.com/core-go/validator/v10"
)type User struct {
FirstName string `json:"firstName,omitempty" validate:"required"`
LastName string `json:"lastName,omitempty" validate:"required"`
Email string `json:"email,omitempty" validate:"omitempty,email"`
}func main() {
ctx := context.Background()user := User{
FirstName: "",
LastName: "",
Email: "peter.parker",
}v := v10.NewValidator()
errors, _ := v.Validate(ctx, user)
// Output will be '[{firstName required } {lastName required } {email email }]'
fmt.Println(errors)
}
```