Пример
github.com/julienschmidt/httprouter v1.3.0: Param
Проверенный пример — golang github.com/julienschmidt/httprouter v1.3.0: Param. Контракт выполнен на go 1.26 · linux debian/x64 · docker и пройден.
sha256:85ddd7601880e62d96c5c29578d9f1847f09cdfdc6470ecff48f5c22d52da2d6
Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла.
Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди.
MIT-0
Свидетельства выполнения
Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.
- Основа свидетельства
- Подписанный контракт пройден
- Квитанции проверки
- 1
- Ключи подписи, собравшие его
- 1
Заявленная среда
go 1.26 linux 24 · ubuntu · glibc 2.39 amd64 go 1.26 go 1.26 go 1
Среды запусков проверки
| Окружение | Контракт | Этапы | Запуск |
|---|---|---|---|
| go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a… |
2026-09-15 |
Кейс
HOW- Цель
- verify github.com/julienschmidt/httprouter.Param in pkg:golang/github.com/julienschmidt/httprouter@v1.3.0
- Символы
-
- github.com/julienschmidt/httprouter.Param
- Окружение
- go 1.26.6
- Создан
- 2026-09-15T01:21:49Z
Контракт
- httprouter.Param stores URL parameter key and value pairs as exported string fields
- httprouter.Params is an ordered slice of httprouter.Param elements accessible by index
- httprouter.Params ByName retrieves the value corresponding to an existing parameter key
- httprouter.Params ByName returns an empty string when the queried key does not exist
- Router extracts named route wildcards into httprouter.Param instances passed to the Handle callback
- Router extracts multiple named route wildcards and wildcard catch-all parameters into ordered httprouter.Param elements
Файлы
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Исходный код
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify github.com/julienschmidt/httprouter.Param in pkg:golang/github.com/julienschmidt/httprouter@v1.3.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/julienschmidt/httprouter@v1.3.0
Demonstrate these symbols/APIs:
- github.com/julienschmidt/httprouter.Param
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:fd39d964f7ad25616f39703c022cf43a66857c55805285985dde9a431f27de59","contract":["httprouter.Param stores URL parameter key and value pairs as exported string fields","httprouter.Params is an ordered slice of httprouter.Param elements accessible by index","httprouter.Params ByName retrieves the value corresponding to an existing parameter key","httprouter.Params ByName returns an empty string when the queried key does not exist","Router extracts named route wildcards into httprouter.Param instances passed to the Handle callback","Router extracts multiple named route wildcards and wildcard catch-all parameters into ordered httprouter.Param elements"],"goal":"verify github.com/julienschmidt/httprouter.Param in pkg:golang/github.com/julienschmidt/httprouter@v1.3.0","kind":"HOW","packages":["pkg:golang/github.com/julienschmidt/httprouter@v1.3.0"],"schemaVersion":1,"symbols":["github.com/julienschmidt/httprouter.Param"]},"contractCommand":["go","run","./test"],"environment":{"arch":"amd64","compiler":"go","compilerVersion":"1.26.6","distro":"ubuntu","ecosystem":"golang","language":"go","languageVersion":"1.26.6","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","runtime":"go","runtimeVersion":"1.26.6","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/julienschmidt/httprouter@v1.3.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/julienschmidt/httprouter@v1.3.0","symbols":["github.com/julienschmidt/httprouter.Param"],"verifierAdapter":"golang@1"}
module sample
go 1.26.6
require github.com/julienschmidt/httprouter v1.3.0
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"github.com/julienschmidt/httprouter"
)
func main() {
router := httprouter.New()
router.GET("/users/:id", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
idParam := ps.ByName("id")
fmt.Fprintf(w, "User ID: %s\n", idParam)
for _, p := range ps {
fmt.Printf("Param key=%s value=%s\n", p.Key, p.Value)
}
})
req := httptest.NewRequest(http.MethodGet, "/users/42", nil)
rec := httptest.NewRecorder()
router.ServeHTTP(rec, req)
fmt.Printf("Status: %d, Body: %s", rec.Code, rec.Body.String())
}
{
"schemaVersion": 1,
"goal": "verify github.com/julienschmidt/httprouter.Param in pkg:golang/github.com/julienschmidt/httprouter@v1.3.0",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/julienschmidt/httprouter@v1.3.0"
],
"symbols": [
"github.com/julienschmidt/httprouter.Param"
]
}
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"os"
"github.com/julienschmidt/httprouter"
)
func main() {
// Assertion 1: httprouter.Param stores URL parameter key and value pairs as exported string fields
{
p := httprouter.Param{
Key: "category",
Value: "books",
}
if p.Key != "category" || p.Value != "books" {
fmt.Fprintf(os.Stderr, "assertion 1 failed: expected Key='category', Value='books', got Key=%q, Value=%q\n", p.Key, p.Value)
os.Exit(1)
}
}
// Assertion 2: httprouter.Params is an ordered slice of httprouter.Param elements accessible by index
{
ps := httprouter.Params{
{Key: "section", Value: "tech"},
{Key: "article", Value: "101"},
}
if len(ps) != 2 {
fmt.Fprintf(os.Stderr, "assertion 2 failed: expected len 2, got %d\n", len(ps))
os.Exit(1)
}
if ps[0].Key != "section" || ps[0].Value != "tech" {
fmt.Fprintf(os.Stderr, "assertion 2 failed: index 0 mismatch: %+v\n", ps[0])
os.Exit(1)
}
if ps[1].Key != "article" || ps[1].Value != "101" {
fmt.Fprintf(os.Stderr, "assertion 2 failed: index 1 mismatch: %+v\n", ps[1])
os.Exit(1)
}
}
// Assertion 3: httprouter.Params ByName retrieves the value corresponding to an existing parameter key
{
ps := httprouter.Params{
{Key: "lang", Value: "golang"},
{Key: "version", Value: "1.3.0"},
}
val := ps.ByName("lang")
if val != "golang" {
fmt.Fprintf(os.Stderr, "assertion 3 failed: expected 'golang', got %q\n", val)
os.Exit(1)
}
val2 := ps.ByName("version")
if val2 != "1.3.0" {
fmt.Fprintf(os.Stderr, "assertion 3 failed: expected '1.3.0', got %q\n", val2)
os.Exit(1)
}
}
// Assertion 4: httprouter.Params ByName returns an empty string when the queried key does not exist
{
ps := httprouter.Params{
{Key: "name", Value: "test"},
}
val := ps.ByName("missing")
if val != "" {
fmt.Fprintf(os.Stderr, "assertion 4 failed: expected empty string, got %q\n", val)
os.Exit(1)
}
}
// Assertion 5: Router extracts named route wildcards into httprouter.Param instances passed to the Handle callback
{
router := httprouter.New()
var capturedParams httprouter.Params
var called bool
router.GET("/items/:itemId", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
called = true
capturedParams = ps
w.WriteHeader(http.StatusOK)
})
req := httptest.NewRequest(http.MethodGet, "/items/sku-9876", nil)
rec := httptest.NewRecorder()
router.ServeHTTP(rec, req)
if !called {
fmt.Fprintf(os.Stderr, "assertion 5 failed: route handler was not called\n")
os.Exit(1)
}
if rec.Code != http.StatusOK {
fmt.Fprintf(os.Stderr, "assertion 5 failed: expected status 200, got %d\n", rec.Code)
os.Exit(1)
}
if len(capturedParams) != 1 {
fmt.Fprintf(os.Stderr, "assertion 5 failed: expected 1 param, got %d\n", len(capturedParams))
os.Exit(1)
}
p := capturedParams[0]
if p.Key != "itemId" || p.Value != "sku-9876" {
fmt.Fprintf(os.Stderr, "assertion 5 failed: param mismatch: Key=%q, Value=%q\n", p.Key, p.Value)
os.Exit(1)
}
if capturedParams.ByName("itemId") != "sku-9876" {
fmt.Fprintf(os.Stderr, "assertion 5 failed: ByName mismatch: got %q\n", capturedParams.ByName("itemId"))
os.Exit(1)
}
}
// Assertion 6: Router extracts multiple named route wildcards and wildcard catch-all parameters into ordered httprouter.Param elements
{
router := httprouter.New()
var capturedParams httprouter.Params
var called bool
router.GET("/orgs/:orgId/repos/:repoName/*subpath", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
called = true
capturedParams = ps
w.WriteHeader(http.StatusOK)
})
req := httptest.NewRequest(http.MethodGet, "/orgs/golang/repos/go/src/net/http", nil)
rec := httptest.NewRecorder()
router.ServeHTTP(rec, req)
if !called {
fmt.Fprintf(os.Stderr, "assertion 6 failed: route handler was not called\n")
os.Exit(1)
}
if len(capturedParams) != 3 {
fmt.Fprintf(os.Stderr, "assertion 6 failed: expected 3 params, got %d\n", len(capturedParams))
os.Exit(1)
}
if capturedParams[0].Key != "orgId" || capturedParams[0].Value != "golang" {
fmt.Fprintf(os.Stderr, "assertion 6 failed: param 0 mismatch: %+v\n", capturedParams[0])
os.Exit(1)
}
if capturedParams[1].Key != "repoName" || capturedParams[1].Value != "go" {
fmt.Fprintf(os.Stderr, "assertion 6 failed: param 1 mismatch: %+v\n", capturedParams[1])
os.Exit(1)
}
if capturedParams[2].Key != "subpath" || capturedParams[2].Value != "/src/net/http" {
fmt.Fprintf(os.Stderr, "assertion 6 failed: param 2 mismatch: %+v\n", capturedParams[2])
os.Exit(1)
}
}
fmt.Println("All contract assertions passed successfully.")
}
Исходный сидер
аноним