-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Added support for validating OCI tags #1372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MadsRC
wants to merge
3
commits into
go-playground:master
Choose a base branch
from
MadsRC:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+81
−29
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| Package validator | ||
| ================= | ||
|
|
||
| <img align="right" src="logo.png"> | ||
| [](https://github.com/go-playground/validator/actions) | ||
| [](https://coveralls.io/github/go-playground/validator?branch=master) | ||
|
|
@@ -11,15 +12,15 @@ Package validator implements value validations for structs and individual fields | |
|
|
||
| It has the following **unique** features: | ||
|
|
||
| - Cross Field and Cross Struct validations by using validation tags or custom validators. | ||
| - Slice, Array and Map diving, which allows any or all levels of a multidimensional field to be validated. | ||
| - Ability to dive into both map keys and values for validation | ||
| - Handles type interface by determining it's underlying type prior to validation. | ||
| - Handles custom field types such as sql driver Valuer see [Valuer](https://golang.org/src/database/sql/driver/types.go?s=1210:1293#L29) | ||
| - Alias validation tags, which allows for mapping of several validations to a single tag for easier defining of validations on structs | ||
| - 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 | ||
| - Customizable i18n aware error messages. | ||
| - 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) | ||
| - Cross Field and Cross Struct validations by using validation tags or custom validators. | ||
| - Slice, Array and Map diving, which allows any or all levels of a multidimensional field to be validated. | ||
| - Ability to dive into both map keys and values for validation | ||
| - Handles type interface by determining it's underlying type prior to validation. | ||
| - Handles custom field types such as sql driver Valuer see [Valuer](https://golang.org/src/database/sql/driver/types.go?s=1210:1293#L29) | ||
| - Alias validation tags, which allows for mapping of several validations to a single tag for easier defining of validations on structs | ||
| - 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 | ||
| - Customizable i18n aware error messages. | ||
| - 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) | ||
|
|
||
| A Call for Maintainers | ||
| ---------------------- | ||
|
|
@@ -31,11 +32,11 @@ Installation | |
|
|
||
| Use go get. | ||
|
|
||
| go get github.com/go-playground/validator/v10 | ||
| go get github.com/go-playground/validator/v10 | ||
|
|
||
| Then import the validator package into your own code. | ||
|
|
||
| import "github.com/go-playground/validator/v10" | ||
| import "github.com/go-playground/validator/v10" | ||
|
|
||
| Error Return Value | ||
| ------- | ||
|
|
@@ -44,8 +45,8 @@ Validation functions return type error | |
|
|
||
| They return type error to avoid the issue discussed in the following, where err is always != nil: | ||
|
|
||
| * http://stackoverflow.com/a/29138676/3158232 | ||
| * https://github.com/go-playground/validator/issues/134 | ||
| - <http://stackoverflow.com/a/29138676/3158232> | ||
| - <https://github.com/go-playground/validator/issues/134> | ||
|
|
||
| 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: | ||
|
|
||
|
|
@@ -57,9 +58,9 @@ validationErrors := err.(validator.ValidationErrors) | |
| Usage and documentation | ||
| ------ | ||
|
|
||
| Please see https://pkg.go.dev/github.com/go-playground/validator/v10 for detailed usage docs. | ||
| Please see <https://pkg.go.dev/github.com/go-playground/validator/v10> for detailed usage docs. | ||
|
|
||
| ##### Examples: | ||
| ##### Examples | ||
|
|
||
| - [Simple](https://github.com/go-playground/validator/blob/master/_examples/simple/main.go) | ||
| - [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 | |
| Baked-in Validations | ||
| ------ | ||
|
|
||
| ### Special Notes: | ||
| ### Special Notes | ||
|
|
||
| - 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. | ||
|
|
||
| ```go | ||
| validate := validator.New(validator.WithRequiredStructEnabled()) | ||
| ``` | ||
|
|
||
| ### Fields: | ||
| ### Fields | ||
|
|
||
| | Tag | Description | | ||
| | - | - | | ||
|
|
@@ -96,7 +99,7 @@ validate := validator.New(validator.WithRequiredStructEnabled()) | |
| | necsfield | Field Does Not Equal Another Field (relative) | | ||
| | nefield | Field Does Not Equal Another Field | | ||
|
|
||
| ### Network: | ||
| ### Network | ||
|
|
||
| | Tag | Description | | ||
| | - | - | | ||
|
|
@@ -128,7 +131,7 @@ validate := validator.New(validator.WithRequiredStructEnabled()) | |
| | url_encoded | URL Encoded | | ||
| | urn_rfc2141 | Urn RFC 2141 String | | ||
|
|
||
| ### Strings: | ||
| ### Strings | ||
|
|
||
| | Tag | Description | | ||
| | - | - | | ||
|
|
@@ -155,7 +158,8 @@ validate := validator.New(validator.WithRequiredStructEnabled()) | |
| | startswith | Starts With | | ||
| | uppercase | Uppercase | | ||
|
|
||
| ### Format: | ||
| ### Format | ||
|
|
||
| | Tag | Description | | ||
| | - | - | | ||
| | base64 | Base64 String | | ||
|
|
@@ -211,6 +215,7 @@ validate := validator.New(validator.WithRequiredStructEnabled()) | |
| | uuid_rfc4122 | Universally Unique Identifier UUID RFC4122 | | ||
| | md4 | MD4 hash | | ||
| | md5 | MD5 hash | | ||
| | oci_tag | Open Container Initiative (OCI) Tag | | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we maybe leave this and remove all the other formatting changes? Otherwise, it doesn't feel clear and should probably be cleaned up in a different PR. There are small things like some lost/changed formatting here and there that I would rather not make part of this PR. |
||
| | sha256 | SHA256 hash | | ||
| | sha384 | SHA384 hash | | ||
| | sha512 | SHA512 hash | | ||
|
|
@@ -223,7 +228,8 @@ validate := validator.New(validator.WithRequiredStructEnabled()) | |
| | ulid | Universally Unique Lexicographically Sortable Identifier ULID | | ||
| | cve | Common Vulnerabilities and Exposures Identifier (CVE id) | | ||
|
|
||
| ### Comparisons: | ||
| ### Comparisons | ||
|
|
||
| | Tag | Description | | ||
| | - | - | | ||
| | eq | Equals | | ||
|
|
@@ -235,7 +241,8 @@ validate := validator.New(validator.WithRequiredStructEnabled()) | |
| | ne | Not Equal | | ||
| | ne_ignore_case | Not Equal ignoring case | | ||
|
|
||
| ### Other: | ||
| ### Other | ||
|
|
||
| | Tag | Description | | ||
| | - | - | | ||
| | dir | Existing Directory | | ||
|
|
@@ -263,15 +270,18 @@ validate := validator.New(validator.WithRequiredStructEnabled()) | |
| | excluded_without_all | Excluded Without All | | ||
| | unique | Unique | | ||
|
|
||
| #### Aliases: | ||
| #### Aliases | ||
|
|
||
| | Tag | Description | | ||
| | - | - | | ||
| | iscolor | hexcolor\|rgb\|rgba\|hsl\|hsla | | ||
| | country_code | iso3166_1_alpha2\|iso3166_1_alpha3\|iso3166_1_alpha_numeric | | ||
|
|
||
| Benchmarks | ||
| ------ | ||
|
|
||
| ###### Run on MacBook Pro Max M3 | ||
|
|
||
| ```go | ||
| go version go1.23.3 darwin/arm64 | ||
| goos: darwin | ||
|
|
@@ -347,8 +357,8 @@ Complementary Software | |
|
|
||
| Here is a list of software that complements using this library either pre or post validation. | ||
|
|
||
| * [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. | ||
| * [mold](https://github.com/go-playground/mold) - A general library to help modify or set data within data structures and other objects | ||
| - [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. | ||
| - [mold](https://github.com/go-playground/mold) - A general library to help modify or set data within data structures and other objects | ||
|
|
||
| How to Contribute | ||
| ------ | ||
|
|
@@ -360,20 +370,22 @@ Maintenance and support for SDK major versions | |
|
|
||
| See prior discussion [here](https://github.com/go-playground/validator/discussions/1342) for more details. | ||
|
|
||
| This package is aligned with the [Go release policy](https://go.dev/doc/devel/release) in that support is guaranteed for | ||
| This package is aligned with the [Go release policy](https://go.dev/doc/devel/release) in that support is guaranteed for | ||
| the two most recent major versions. | ||
|
|
||
| This does not mean the package will not work with older versions of Go, only that we reserve the right to increase the | ||
| MSGV(Minimum Supported Go Version) when the need arises to address Security issues/patches, OS issues & support or newly | ||
| This does not mean the package will not work with older versions of Go, only that we reserve the right to increase the | ||
| MSGV(Minimum Supported Go Version) when the need arises to address Security issues/patches, OS issues & support or newly | ||
| introduced functionality that would greatly benefit the maintenance and/or usage of this package. | ||
|
|
||
| If and when the MSGV is increased it will be done so in a minimum of a `Minor` release bump. | ||
|
|
||
| License | ||
| ------- | ||
|
|
||
| Distributed under MIT License, please see license file within the code for more details. | ||
|
|
||
| Maintainers | ||
| ----------- | ||
|
|
||
| This project has grown large enough that more than one person is required to properly support the community. | ||
| If you are interested in becoming a maintainer please reach out to me https://github.com/deankarn | ||
| If you are interested in becoming a maintainer please reach out to me <https://github.com/deankarn> | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation was on purpose to render the command as code. Not it is displayed as standard text.