Skip to content

Commit 5c40a75

Browse files
committed
feat: resolve merge conflict
2 parents 82b9290 + 6a38036 commit 5c40a75

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+11733
-2815
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Bug Report
2+
description: File a bug report
3+
title: "[Bug]: "
4+
labels: ["bug"]
5+
body:
6+
- type: markdown
7+
attributes:
8+
value: |
9+
Thanks for taking the time to fill out this bug report!
10+
- type: textarea
11+
id: what-happened
12+
attributes:
13+
label: What happened?
14+
description: Also tell us, what did you expect to happen?
15+
validations:
16+
required: true
17+
- type: textarea
18+
id: version
19+
attributes:
20+
label: Version
21+
description: What version of validator are you running?
22+
validations:
23+
required: true
24+
- type: textarea
25+
id: code
26+
attributes:
27+
label: Example Code
28+
description: Please provide a code example that demonstrates the issue
29+
render: go
30+
validations:
31+
required: true

.github/dependabot.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: 2
2+
updates:
3+
# Maintain dependencies for Golang
4+
- package-ecosystem: gomod
5+
directory: "/"
6+
schedule:
7+
interval: weekly
8+
# Maintain dependencies for GitHub Actions
9+
- package-ecosystem: github-actions
10+
directory: "/"
11+
schedule:
12+
interval: weekly

.github/workflows/go.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
on:
2+
push:
3+
branches:
4+
- master
5+
6+
name: Test
7+
jobs:
8+
test:
9+
strategy:
10+
matrix:
11+
go-version: [1.24.x, 1.25.x]
12+
os: [ubuntu-latest]
13+
runs-on: ${{ matrix.os }}
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v5
17+
18+
- name: Install Go
19+
uses: actions/setup-go@v6
20+
with:
21+
go-version: ${{ matrix.go-version }}
22+
23+
- name: Test
24+
run: go test -race ./...

.github/workflows/workflow.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ jobs:
88
test:
99
strategy:
1010
matrix:
11-
go-version: [1.20.x,1.21.x,1.22.x,1.23.x]
11+
go-version: [1.24.x, 1.25.x]
1212
os: [ubuntu-latest, macos-latest, windows-latest]
1313
runs-on: ${{ matrix.os }}
1414
steps:
1515
- name: Checkout code
16-
uses: actions/checkout@v4
16+
uses: actions/checkout@v5
1717

1818
- name: Install Go
19-
uses: actions/setup-go@v5
19+
uses: actions/setup-go@v6
2020
with:
2121
go-version: ${{ matrix.go-version }}
2222

2323
- name: Test
2424
run: go test -race -covermode=atomic -coverprofile="profile.cov" ./...
2525

2626
- name: Send Coverage
27-
if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.22.x'
27+
if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.24.x'
2828
uses: shogo82148/actions-goveralls@v1
2929
with:
3030
path-to-profile: profile.cov
@@ -33,11 +33,11 @@ jobs:
3333
name: lint
3434
runs-on: ubuntu-latest
3535
steps:
36-
- uses: actions/checkout@v4
37-
- uses: actions/setup-go@v5
36+
- uses: actions/checkout@v5
37+
- uses: actions/setup-go@v6
3838
with:
39-
go-version: 1.23.x
39+
go-version: 1.24.x
4040
- name: golangci-lint
41-
uses: golangci/golangci-lint-action@v4
41+
uses: golangci/golangci-lint-action@v8
4242
with:
43-
version: latest
43+
version: latest

.golangci.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
version: "2"
2+
linters:
3+
default: all
4+
disable:
5+
- noinlineerr
6+
- wsl_v5
7+
- copyloopvar
8+
- cyclop
9+
- depguard
10+
- dogsled
11+
- dupl
12+
- dupword
13+
- err113
14+
- errorlint
15+
- exhaustive
16+
- exhaustruct
17+
- forbidigo
18+
- forcetypeassert
19+
- funlen
20+
- gochecknoglobals
21+
- gocognit
22+
- goconst
23+
- gocritic
24+
- gocyclo
25+
- godot
26+
- gosec
27+
- gosmopolitan
28+
- interfacebloat
29+
- intrange
30+
- ireturn
31+
- lll
32+
- maintidx
33+
- misspell
34+
- mnd
35+
- nakedret
36+
- nestif
37+
- nilnil
38+
- nlreturn
39+
- nonamedreturns
40+
- paralleltest
41+
- perfsprint
42+
- prealloc
43+
- recvcheck
44+
- revive
45+
- staticcheck
46+
- tagalign
47+
- tagliatelle
48+
- testpackage
49+
- thelper
50+
- tparallel
51+
- unparam
52+
- varnamelen
53+
- wrapcheck
54+
- wsl

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ GOCMD=go
33
linters-install:
44
@golangci-lint --version >/dev/null 2>&1 || { \
55
echo "installing linting tools..."; \
6-
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s v1.41.1; \
6+
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s v2.0.2; \
77
}
88

99
lint: linters-install

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
Package validator
22
=================
3-
<img align="right" src="logo.png">[![Join the chat at https://gitter.im/go-playground/validator](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/go-playground/validator?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4-
![Project status](https://img.shields.io/badge/version-10.24.0-green.svg)
3+
<img align="right" src="logo.png">[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/go-playground/validator)](https://github.com/go-playground/validator/releases)
54
[![Build Status](https://github.com/go-playground/validator/actions/workflows/workflow.yml/badge.svg)](https://github.com/go-playground/validator/actions)
65
[![Coverage Status](https://coveralls.io/repos/go-playground/validator/badge.svg?branch=master&service=github)](https://coveralls.io/github/go-playground/validator?branch=master)
76
[![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/validator)](https://goreportcard.com/report/github.com/go-playground/validator)
@@ -107,8 +106,9 @@ validate := validator.New(validator.WithRequiredStructEnabled())
107106
| datauri | Data URL |
108107
| fqdn | Full Qualified Domain Name (FQDN) |
109108
| hostname | Hostname RFC 952 |
110-
| hostname_port | HostPort |
111109
| hostname_rfc1123 | Hostname RFC 1123 |
110+
| hostname_port | HostPort |
111+
| port | Port number |
112112
| ip | Internet Protocol Address IP |
113113
| ip4_addr | Internet Protocol Address IPv4 |
114114
| ip6_addr | Internet Protocol Address IPv6 |
@@ -125,7 +125,8 @@ validate := validator.New(validator.WithRequiredStructEnabled())
125125
| unix_addr | Unix domain socket end point Address |
126126
| uri | URI String |
127127
| url | URL String |
128-
| http_url | HTTP URL String |
128+
| http_url | HTTP(s) URL String |
129+
| https_url | HTTPS-only URL String |
129130
| url_encoded | URL Encoded |
130131
| urn_rfc2141 | Urn RFC 2141 String |
131132

@@ -134,6 +135,7 @@ validate := validator.New(validator.WithRequiredStructEnabled())
134135
| Tag | Description |
135136
| - | - |
136137
| alpha | Alpha Only |
138+
| alphaspace | Alpha Space |
137139
| alphanum | Alphanumeric |
138140
| alphanumunicode | Alphanumeric Unicode |
139141
| alphaunicode | Alpha Unicode |
@@ -173,6 +175,7 @@ validate := validator.New(validator.WithRequiredStructEnabled())
173175
| spicedb | SpiceDb ObjectID/Permission/Type |
174176
| datetime | Datetime |
175177
| e164 | e164 formatted phone number |
178+
| ein | U.S. Employeer Identification Number |
176179
| email | E-mail String
177180
| eth_addr | Ethereum Address |
178181
| hexadecimal | Hexadecimal String |
@@ -262,6 +265,8 @@ validate := validator.New(validator.WithRequiredStructEnabled())
262265
| excluded_without | Excluded Without |
263266
| excluded_without_all | Excluded Without All |
264267
| unique | Unique |
268+
| validateFn | Verify if the method `Validate() error` does not return an error (or any specified method) |
269+
265270

266271
#### Aliases:
267272
| Tag | Description |
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"errors"
6+
"net/http"
7+
"strings"
8+
9+
"github.com/go-playground/locales/en"
10+
"github.com/go-playground/locales/zh"
11+
"github.com/go-playground/locales/zh_Hant_TW"
12+
ut "github.com/go-playground/universal-translator"
13+
"github.com/go-playground/validator/v10"
14+
en_translations "github.com/go-playground/validator/v10/translations/en"
15+
zh_translations "github.com/go-playground/validator/v10/translations/zh"
16+
zh_tw_translations "github.com/go-playground/validator/v10/translations/zh_tw"
17+
)
18+
19+
var uni *ut.UniversalTranslator
20+
21+
// This example showcases how to use the Validator and UniversalTranslator with both Simplified and Traditional Chinese languages.
22+
// To run the example:
23+
// Step 1: go run _examples/http-transalations/main.go
24+
// Step 2 - Simplified Chinese: curl -d '{"first_name":"foo"}' -H "Accept-Language: zh" -H "Content-Type: application/json" -X POST http://localhost:8081/users
25+
// Step 3 - Traditional Chinese: curl -d '{"first_name":"foo"}' -H "Accept-Language: zh-Hant-TW" -H "Content-Type: application/json" -X POST http://localhost:8081/users
26+
func main() {
27+
validate := validator.New()
28+
en := en.New()
29+
uni = ut.New(en, en, zh.New(), zh_Hant_TW.New())
30+
31+
validate = validator.New()
32+
enTrans, _ := uni.GetTranslator("en")
33+
en_translations.RegisterDefaultTranslations(validate, enTrans)
34+
zhTrans, _ := uni.GetTranslator("zh")
35+
zh_translations.RegisterDefaultTranslations(validate, zhTrans)
36+
zhHantTrans, _ := uni.GetTranslator("zh_Hant_TW")
37+
zh_tw_translations.RegisterDefaultTranslations(validate, zhHantTrans)
38+
39+
type User struct {
40+
FirstName string `json:"first_name" validate:"required"`
41+
LastName string `json:"last_name" validate:"required"`
42+
}
43+
44+
http.HandleFunc("/users", func(w http.ResponseWriter, r *http.Request) {
45+
// ... fill user value
46+
var user User
47+
48+
// Header Accept-Language value is en or zh
49+
trans, _ := uni.GetTranslator(strings.Replace(r.Header.Get("Accept-Language"), "-", "_", -1))
50+
if err := validate.Struct(&user); err != nil {
51+
var errs validator.ValidationErrors
52+
var httpErrors []validator.ValidationErrorsTranslations
53+
if errors.As(err, &errs) {
54+
httpErrors = append(httpErrors, errs.Translate(trans))
55+
}
56+
r, _ := json.Marshal(httpErrors)
57+
w.Write(r)
58+
}
59+
})
60+
61+
http.ListenAndServe(":8081", nil)
62+
}

_examples/simple/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ func validateStruct() {
6262
// this check is only needed when your code could produce
6363
// an invalid value for validation such as interface with nil
6464
// value most including myself do not usually have code like this.
65-
if errors.As(err, &validator.InvalidValidationError{}) {
65+
var invalidValidationError *validator.InvalidValidationError
66+
if errors.As(err, &invalidValidationError) {
6667
fmt.Println(err)
6768
return
6869
}

0 commit comments

Comments
 (0)