CodeSampleX

Exemplo

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

Amostra 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 rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
2
Chaves de assinatura que o compilaram
2
Ambiente declarado go 1.26 linux x64 go 1.26 go go

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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
Pacotes
Símbolos
  • gin.New
  • Engine.Use
  • Engine.POST
  • Engine.ServeHTTP
  • Context.ShouldBindJSON
  • Context.Set
  • Context.GetString
  • Context.AbortWithStatusJSON
  • Context.IsAborted
  • Context.Next
Ambiente
go 1.26
Criado
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

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Seeder de origem

csx-seed