https://github.com/accelbyte/justice-input-validation-go
https://github.com/accelbyte/justice-input-validation-go
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/accelbyte/justice-input-validation-go
- Owner: AccelByte
- License: apache-2.0
- Created: 2019-07-31T06:46:08.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-08-23T03:50:35.000Z (over 1 year ago)
- Last Synced: 2024-08-23T04:48:24.622Z (over 1 year ago)
- Language: Go
- Size: 41 KB
- Stars: 0
- Watchers: 5
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# justice-input-validation-go
This is AccelByte Justice Golang Input Validation package. This package is extending functionality from [govalidator](https://github.com/asaskevich/govalidator) and add some additional rule to it.
## Usage
#### Importing package
```go
import validator "github.com/AccelByte/justice-input-validation-go"
```
#### Validating struct from request data model
We can validate a struct that have validation tag literal with validateStruct() method
```go
import validator "github.com/AccelByte/justice-input-validation-go"
// example of a request model
type requestModel struct {
Name string `valid:"displayName"`
Email string `valid:"email"`
}
reqData = requestModel{
Name: "Jhon Doe",
Email: "jhon@mail.com",
}
// validating struct
if valid, err := validator.ValidateStruct(reqData); !valid || err {
// do something when reqData is invalid
}
```
#### List of available validators with its corresponding function that defined in rules.go file
```go
"tag" : IsTag
"language" : IsLanguage
"topic" : IsTopic
"displayName" : IsDisplayName
"personName" : IsPersonName
"uuid4WithoutHyphens" : IsUUID4WithoutHyphens
"permissionResource" : IsPermissionResource
"path" : IsPath
"url" : IsURL
"uri" : IsURI
"dateTime" : IsDateTime
"date" : IsDate
"jwt" : IsJWT
"password" : IsPassword
"email" : IsEmail
"codeChallenge" : IsCodeChallenge
"notContainWhitespace" : IsNotContainWhitespace
"containWhitespace" : IsContainWhitespace
"country" : IsCountry
"namespace" : IsNamespace
```
And of course this package is not limiting the functionality that came from [govalidator](https://github.com/asaskevich/govalidator) package, you can use all available validation rules that supported by [govalidator](https://github.com/asaskevich/govalidator) package.