Пример
Validate JSON with ShouldBindJSON and stop a Gin handler chain without falling through after Abort
sha256:403c56901efe4436738071fb04de2008bb9bb3d0785ec2d1be1216037744672e
PUBLISHED
L3_CONTRACT_PASS
MIT-0
Кейс
- Цель
- Validate JSON with ShouldBindJSON and stop a Gin handler chain without falling through after Abort HOW
- Пакеты
- github.com/gin-gonic/gin v1.12.0
- Окружение
- go 1.26
- Создан
- 2026-08-17T03:14:37Z
Что обычно предполагают
AbortWithStatusJSON immediately returns from the current handler, so code after it cannot run and an explicit return is unnecessary.
Автор образца записал здесь то, чего ожидал бы разработчик или модель. Контракт ниже — это то, что действительно выполнялось.
Контракт
- assert binding an empty required name with ShouldBindJSON lets the handler choose HTTP 422 and a JSON error response
- assert AbortWithStatusJSON marks the context aborted and skips the next route handler but code after AbortWithStatusJSON in the current handler still executes
- assert an explicit return after AbortWithStatusJSON prevents current-handler fallthrough as well as downstream-handler execution
- assert middleware context values and a validated JSON name flow to the next handler on a valid request
- assert all requests run through httptest and Engine.ServeHTTP without opening a network listener
Файлы
- NOTES.md
- csx.json
- go.mod
- go.sum
- router.go
- router_test.go
Скачать проверенный артефакт (tar.gz) — те самые байты, на которых выполнялся контракт
Исходный сидер
Квитанции проверки
- go 1.26 · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · golang@1 · 2026-08-17 · ed25519:d91480838ac982c9