Sample
Configure struct-level required validation in go-playground/validator using WithRequiredStructEnabled to prevent zero-value nested structs from silently passing
sha256:274f2408437f66d1322945c98d90081c192c2187a49bd49dff5805e7f7795c54
PUBLISHED
L3_CONTRACT_PASS
MIT-0
Execution evidence
Declared environment and signed verification runs are separated so you can see exactly what this sample proves.
Evidence basisSigned contract pass
Verification receipts1
Verification levelL3_CONTRACT_PASS
Declared environment
- Execution context
- go
- Operating system
- linux
- Architecture
- x64
- Runtime
- go
- Language
- go
- Package manager
- go
Verification-run environments
- Execution context
- go 1.26
- Operating system
- linux alpine · musl
- Architecture
- x64
- Runtime
- go 1.26
- Language
- go
- Package manager
- go
- Execution
- container · docker
CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · golang@1 · 2026-08-17
Case
- Goal
- Configure struct-level required validation in go-playground/validator using WithRequiredStructEnabled to prevent zero-value nested structs from silently passing HOW
- Packages
-
github.com/go-playground/validator/v10 10.30.3
- Environment
- go
- Created
- 2026-08-17T12:35:13Z
Commonly assumed
Tagging a non-pointer struct field with validate:"required" causes validator.New().Struct() to reject an uninitialized zero-value struct.
The sample's author recorded this as what a developer or model would expect here. The contract below is what actually ran.
Contract
- validator.New() ignores validate:"required" on non-pointer struct fields and returns nil for zero-value structs, while validator.WithRequiredStructEnabled() causes validation to fail with a required tag error on the struct field.
- Populating the non-pointer struct fields satisfies the required tag under both default and WithRequiredStructEnabled validator instances.
- Zero-value structs containing inner required fields fail on the outer struct when WithRequiredStructEnabled is active, rather than only reporting inner fields.
Files
- NOTES.md
- config.go
- config_test.go
- csx.json
- go.mod
- go.sum
Download the source artifact (tar.gz)
Origin Seeder
csx-seed
Verification receipts
- go 1.26 · linux alpine/x64 · docker · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · golang@1 · 2026-08-17 · ed25519:d91480838ac982c9