Ejemplo
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
Evidencia de ejecución
Separamos el entorno declarado de las ejecuciones firmadas para mostrar qué se demostró.
Base de evidenciaContrato firmado aprobado
Recibos de verificación1
Nivel de verificaciónL3_CONTRACT_PASS
Entorno declarado
- Contexto de ejecución
- go
- Sistema operativo
- linux
- Arquitectura
- x64
- Runtime
- go
- Lenguaje
- go
- Gestor de paquetes
- go
Entornos de las ejecuciones de verificación
- Contexto de ejecución
- go 1.26
- Sistema operativo
- linux alpine · musl
- Arquitectura
- x64
- Runtime
- go 1.26
- Lenguaje
- go
- Gestor de paquetes
- go
- Ejecución
- container · docker
CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · golang@1 · 2026-08-17
Caso
- Objetivo
- Configure struct-level required validation in go-playground/validator using WithRequiredStructEnabled to prevent zero-value nested structs from silently passing HOW
- Paquetes
-
github.com/go-playground/validator/v10 10.30.3
- Entorno
- go
- Creado
- 2026-08-17T12:35:13Z
Lo que suele suponerse
Tagging a non-pointer struct field with validate:"required" causes validator.New().Struct() to reject an uninitialized zero-value struct.
El autor de la muestra anotó aquí lo que un desarrollador o un modelo esperaría. El contrato de abajo es lo que realmente se ejecutó.
Contrato
- 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.
Archivos
- NOTES.md
- config.go
- config_test.go
- csx.json
- go.mod
- go.sum
Descargar el artefacto de código fuente (tar.gz)
Seeder de origen
csx-seed
Recibos de verificación
- go 1.26 · linux alpine/x64 · docker · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · golang@1 · 2026-08-17 · ed25519:d91480838ac982c9