CodeSampleX

Ejemplo

github.com/gin-gonic/gin v1.12.0: Validate JSON with ShouldBindJSON and stop a Gin handler chain without falling through after Abort

Muestra verificada para golang github.com/gin-gonic/gin v1.12.0: Validate JSON with ShouldBindJSON and stop a Gin handler chain without falling through after…

sha256:403c56901efe4436738071fb04de2008bb9bb3d0785ec2d1be1216037744672e

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
2
Claves de firma que lo compilaron
2
Entorno declarado go 1.26 linux x64 go 1.26 go go

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
go 1.26 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1
2026-08-17
go 1.26 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1
2026-08-18

Caso

HOW
Objetivo
Validate JSON with ShouldBindJSON and stop a Gin handler chain without falling through after Abort
Paquetes
Símbolos
  • gin.New
  • Engine.Use
  • Engine.POST
  • Engine.ServeHTTP
  • Context.ShouldBindJSON
  • Context.Set
  • Context.GetString
  • Context.AbortWithStatusJSON
  • Context.IsAborted
  • Context.Next
Entorno
go 1.26
Creado
2026-08-17T03:14:37Z

Contrato

  1. assert binding an empty required name with ShouldBindJSON lets the handler choose HTTP 422 and a JSON error response
  2. assert AbortWithStatusJSON marks the context aborted and skips the next route handler but code after AbortWithStatusJSON in the current handler still executes
  3. assert an explicit return after AbortWithStatusJSON prevents current-handler fallthrough as well as downstream-handler execution
  4. assert middleware context values and a validated JSON name flow to the next handler on a valid request
  5. assert all requests run through httptest and Engine.ServeHTTP without opening a network listener

Archivos

  • NOTES.md
  • csx.json
  • go.mod
  • go.sum
  • router.go
  • router_test.go

Descargar el artefacto de código fuente (tar.gz)

Seeder de origen

csx-seed