Skip to content

Commit 4a694d2

Browse files
committed
Updated documentation and fixed missing brace left out from last merge
1 parent d2ed55d commit 4a694d2

File tree

3 files changed

+48
-29
lines changed

3 files changed

+48
-29
lines changed

README.md

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Package validator
22
=================
3+
34
<img align="right" src="logo.png">![Project status](https://img.shields.io/badge/version-10.25.0-green.svg)
45
[![Build Status](https://github.com/go-playground/validator/actions/workflows/workflow.yml/badge.svg)](https://github.com/go-playground/validator/actions)
56
[![Coverage Status](https://coveralls.io/repos/go-playground/validator/badge.svg?branch=master&service=github)](https://coveralls.io/github/go-playground/validator?branch=master)
@@ -11,15 +12,15 @@ Package validator implements value validations for structs and individual fields
1112

1213
It has the following **unique** features:
1314

14-
- Cross Field and Cross Struct validations by using validation tags or custom validators.
15-
- Slice, Array and Map diving, which allows any or all levels of a multidimensional field to be validated.
16-
- Ability to dive into both map keys and values for validation
17-
- Handles type interface by determining it's underlying type prior to validation.
18-
- Handles custom field types such as sql driver Valuer see [Valuer](https://golang.org/src/database/sql/driver/types.go?s=1210:1293#L29)
19-
- Alias validation tags, which allows for mapping of several validations to a single tag for easier defining of validations on structs
20-
- Extraction of custom defined Field Name e.g. can specify to extract the JSON name while validating and have it available in the resulting FieldError
21-
- Customizable i18n aware error messages.
22-
- Default validator for the [gin](https://github.com/gin-gonic/gin) web framework; upgrading from v8 to v9 in gin see [here](https://github.com/go-playground/validator/tree/master/_examples/gin-upgrading-overriding)
15+
- Cross Field and Cross Struct validations by using validation tags or custom validators.
16+
- Slice, Array and Map diving, which allows any or all levels of a multidimensional field to be validated.
17+
- Ability to dive into both map keys and values for validation
18+
- Handles type interface by determining it's underlying type prior to validation.
19+
- Handles custom field types such as sql driver Valuer see [Valuer](https://golang.org/src/database/sql/driver/types.go?s=1210:1293#L29)
20+
- Alias validation tags, which allows for mapping of several validations to a single tag for easier defining of validations on structs
21+
- Extraction of custom defined Field Name e.g. can specify to extract the JSON name while validating and have it available in the resulting FieldError
22+
- Customizable i18n aware error messages.
23+
- Default validator for the [gin](https://github.com/gin-gonic/gin) web framework; upgrading from v8 to v9 in gin see [here](https://github.com/go-playground/validator/tree/master/_examples/gin-upgrading-overriding)
2324

2425
A Call for Maintainers
2526
----------------------
@@ -31,11 +32,11 @@ Installation
3132

3233
Use go get.
3334

34-
go get github.com/go-playground/validator/v10
35+
go get github.com/go-playground/validator/v10
3536

3637
Then import the validator package into your own code.
3738

38-
import "github.com/go-playground/validator/v10"
39+
import "github.com/go-playground/validator/v10"
3940

4041
Error Return Value
4142
-------
@@ -44,8 +45,8 @@ Validation functions return type error
4445

4546
They return type error to avoid the issue discussed in the following, where err is always != nil:
4647

47-
* http://stackoverflow.com/a/29138676/3158232
48-
* https://github.com/go-playground/validator/issues/134
48+
- <http://stackoverflow.com/a/29138676/3158232>
49+
- <https://github.com/go-playground/validator/issues/134>
4950

5051
Validator returns only InvalidValidationError for bad validation input, nil or ValidationErrors as type error; so, in your code all you need to do is check if the error returned is not nil, and if it's not check if error is InvalidValidationError ( if necessary, most of the time it isn't ) type cast it to type ValidationErrors like so:
5152

@@ -57,9 +58,9 @@ validationErrors := err.(validator.ValidationErrors)
5758
Usage and documentation
5859
------
5960

60-
Please see https://pkg.go.dev/github.com/go-playground/validator/v10 for detailed usage docs.
61+
Please see <https://pkg.go.dev/github.com/go-playground/validator/v10> for detailed usage docs.
6162

62-
##### Examples:
63+
##### Examples
6364

6465
- [Simple](https://github.com/go-playground/validator/blob/master/_examples/simple/main.go)
6566
- [Custom Field Types](https://github.com/go-playground/validator/blob/master/_examples/custom/main.go)
@@ -71,13 +72,15 @@ Please see https://pkg.go.dev/github.com/go-playground/validator/v10 for detaile
7172
Baked-in Validations
7273
------
7374

74-
### Special Notes:
75+
### Special Notes
76+
7577
- If new to using validator it is highly recommended to initialize it using the `WithRequiredStructEnabled` option which is opt-in to new behaviour that will become the default behaviour in v11+. See documentation for more details.
78+
7679
```go
7780
validate := validator.New(validator.WithRequiredStructEnabled())
7881
```
7982

80-
### Fields:
83+
### Fields
8184

8285
| Tag | Description |
8386
| - | - |
@@ -96,7 +99,7 @@ validate := validator.New(validator.WithRequiredStructEnabled())
9699
| necsfield | Field Does Not Equal Another Field (relative) |
97100
| nefield | Field Does Not Equal Another Field |
98101

99-
### Network:
102+
### Network
100103

101104
| Tag | Description |
102105
| - | - |
@@ -128,7 +131,7 @@ validate := validator.New(validator.WithRequiredStructEnabled())
128131
| url_encoded | URL Encoded |
129132
| urn_rfc2141 | Urn RFC 2141 String |
130133

131-
### Strings:
134+
### Strings
132135

133136
| Tag | Description |
134137
| - | - |
@@ -155,7 +158,8 @@ validate := validator.New(validator.WithRequiredStructEnabled())
155158
| startswith | Starts With |
156159
| uppercase | Uppercase |
157160

158-
### Format:
161+
### Format
162+
159163
| Tag | Description |
160164
| - | - |
161165
| base64 | Base64 String |
@@ -211,6 +215,7 @@ validate := validator.New(validator.WithRequiredStructEnabled())
211215
| uuid_rfc4122 | Universally Unique Identifier UUID RFC4122 |
212216
| md4 | MD4 hash |
213217
| md5 | MD5 hash |
218+
| oci_tag | Open Container Initiative (OCI) Tag |
214219
| sha256 | SHA256 hash |
215220
| sha384 | SHA384 hash |
216221
| sha512 | SHA512 hash |
@@ -223,7 +228,8 @@ validate := validator.New(validator.WithRequiredStructEnabled())
223228
| ulid | Universally Unique Lexicographically Sortable Identifier ULID |
224229
| cve | Common Vulnerabilities and Exposures Identifier (CVE id) |
225230

226-
### Comparisons:
231+
### Comparisons
232+
227233
| Tag | Description |
228234
| - | - |
229235
| eq | Equals |
@@ -235,7 +241,8 @@ validate := validator.New(validator.WithRequiredStructEnabled())
235241
| ne | Not Equal |
236242
| ne_ignore_case | Not Equal ignoring case |
237243

238-
### Other:
244+
### Other
245+
239246
| Tag | Description |
240247
| - | - |
241248
| dir | Existing Directory |
@@ -263,15 +270,18 @@ validate := validator.New(validator.WithRequiredStructEnabled())
263270
| excluded_without_all | Excluded Without All |
264271
| unique | Unique |
265272

266-
#### Aliases:
273+
#### Aliases
274+
267275
| Tag | Description |
268276
| - | - |
269277
| iscolor | hexcolor\|rgb\|rgba\|hsl\|hsla |
270278
| country_code | iso3166_1_alpha2\|iso3166_1_alpha3\|iso3166_1_alpha_numeric |
271279

272280
Benchmarks
273281
------
282+
274283
###### Run on MacBook Pro Max M3
284+
275285
```go
276286
go version go1.23.3 darwin/arm64
277287
goos: darwin
@@ -347,8 +357,8 @@ Complementary Software
347357

348358
Here is a list of software that complements using this library either pre or post validation.
349359

350-
* [form](https://github.com/go-playground/form) - Decodes url.Values into Go value(s) and Encodes Go value(s) into url.Values. Dual Array and Full map support.
351-
* [mold](https://github.com/go-playground/mold) - A general library to help modify or set data within data structures and other objects
360+
- [form](https://github.com/go-playground/form) - Decodes url.Values into Go value(s) and Encodes Go value(s) into url.Values. Dual Array and Full map support.
361+
- [mold](https://github.com/go-playground/mold) - A general library to help modify or set data within data structures and other objects
352362

353363
How to Contribute
354364
------
@@ -360,20 +370,22 @@ Maintenance and support for SDK major versions
360370

361371
See prior discussion [here](https://github.com/go-playground/validator/discussions/1342) for more details.
362372

363-
This package is aligned with the [Go release policy](https://go.dev/doc/devel/release) in that support is guaranteed for
373+
This package is aligned with the [Go release policy](https://go.dev/doc/devel/release) in that support is guaranteed for
364374
the two most recent major versions.
365375

366-
This does not mean the package will not work with older versions of Go, only that we reserve the right to increase the
367-
MSGV(Minimum Supported Go Version) when the need arises to address Security issues/patches, OS issues & support or newly
376+
This does not mean the package will not work with older versions of Go, only that we reserve the right to increase the
377+
MSGV(Minimum Supported Go Version) when the need arises to address Security issues/patches, OS issues & support or newly
368378
introduced functionality that would greatly benefit the maintenance and/or usage of this package.
369379

370380
If and when the MSGV is increased it will be done so in a minimum of a `Minor` release bump.
371381

372382
License
373383
-------
384+
374385
Distributed under MIT License, please see license file within the code for more details.
375386

376387
Maintainers
377388
-----------
389+
378390
This project has grown large enough that more than one person is required to properly support the community.
379-
If you are interested in becoming a maintainer please reach out to me https://github.com/deankarn
391+
If you are interested in becoming a maintainer please reach out to me <https://github.com/deankarn>

baked_in.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3071,6 +3071,7 @@ func isCron(fl FieldLevel) bool {
30713071
// isOciTag is the validation function for validating if the current field's value is a valid OCI tag, as described in the OCI Distribution Specification: https://github.com/opencontainers/distribution-spec/blob/main/spec.md
30723072
func isOciTag(fl FieldLevel) bool {
30733073
return ociTagRegex().MatchString(fl.Field().String())
3074+
}
30743075

30753076
// isEIN is the validation function for validating if the current field's value is a valid U.S. Employer Identification Number (EIN)
30763077
func isEIN(fl FieldLevel) bool {

doc.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,12 @@ Example:
14131413
ConnectionStringField string `validate:"mongodb_connection_string"`
14141414
}
14151415
1416+
# OCI Tag
1417+
1418+
This validates that a string value is a valid OCI tag, as defined in the OCI Image Spec.
1419+
1420+
Usage: oci_tag
1421+
14161422
# Cron
14171423
14181424
This validates that a string value contains a valid cron expression.

0 commit comments

Comments
 (0)