示例
github.com/julienschmidt/httprouter v1.3.0: Param
已验证示例 — golang github.com/julienschmidt/httprouter v1.3.0: Param. contract 在 go 1.26 · linux debian/x64 · docker 上运行并通过: httprouter.Param stores URL…
sha256:85ddd7601880e62d96c5c29578d9f1847f09cdfdc6470ecff48f5c22d52da2d6
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
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.")
}
原始种子者
匿名