• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

go-playground / validator / 18261600532
74%
v8: 100%

Build:
Build:
LAST BUILD BRANCH: master
DEFAULT BRANCH: v8
Ran 05 Oct 2025 04:51PM UTC
Jobs 1
Files 34
Run time 1min
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

05 Oct 2025 04:50PM UTC coverage: 73.71% (+0.03%) from 73.684%
18261600532

push

github

web-flow
Fixed missing keys from returned errors in map validation (#1284)

## Fixes Or Enhances

### Bug Description:
The `ValidateMapCtx` function calls the `VarCtx(ctx context.Context,
field interface{}, tag string) (err error)` method, but the returned
errors do not contain keys.
```go
package main

import (
	"fmt"

	"github.com/go-playground/validator/v10"
)

func main() {
	validate := validator.New()

	data := map[string]interface{}{"email": "emailaddress"}
	rules := map[string]interface{}{"email": "required,email"}
	errs := validate.ValidateMap(data, rules) // when VarCtx is called
	fmt.Println(errs)
	//output: map[email:Key: '' Error:Field validation for '' failed on the 'email' tag]
}

```
### Fix:
Added a new method `VarWithKeyCtx(ctx context.Context, key string, field
interface{}, tag string) (err error)` to support validating a single
variable, ensuring that the returned error contains the key of the
field. This retains compatibility with the current `VarCtx(...)` method.
Now, `ValidateMapCtx` will call the new `VarWithKeyCtx(...)` method.
```go
package main

import (
	"fmt"

	"github.com/go-playground/validator/v10"
)

func main() {
	validate := validator.New()

	data := map[string]interface{}{"email": "emailaddress"}
	rules := map[string]interface{}{"email": "required,email"}
	errs := validate.ValidateMap(data, rules) // when the new VarWithKeyCtx is called
	fmt.Println(errs)
	//output: map[email:Key: 'email' Error:Field validation for 'email' failed on the 'email' tag]
}

```

**Make sure that you've checked the boxes below before you submit PR:**
- [x] Tests exist or have been written that cover this particular
change.

@go-playground/validator-maintainers

26 of 28 new or added lines in 1 file covered. (92.86%)

14355 of 19475 relevant lines covered (73.71%)

78.16 hits per line

New Missed Lines in Diff

Lines Coverage ∆ File
2
94.16
-0.12% validator_instance.go
Jobs
ID Job ID Ran Files Coverage
1 18261600532.1 05 Oct 2025 04:51PM UTC 34
73.71
GitHub Action Run
Source Files on build 18261600532
  • Tree
  • List 34
  • Changed 1
  • Source Changed 0
  • Coverage Changed 1
Coverage ∆ File Lines Relevant Covered Missed Hits/Line
  • Back to Repo
  • 13130d2e on github
  • Prev Build on master (#18252681669)
  • Next Build on master (#18261626460)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc