示例
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822: negotiate HTTP Accept header content type using goautoneg
已验证示例 — golang github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822: negotiate HTTP Accept header content type using goautoneg. contract 在 go 1.26…
sha256:045ec8393f3d193b61123170c99aff268d48c04196d0e39a84d7007e4114880e
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
linux 24 · ubuntu · glibc 2.39 x64 go
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f… |
2026-08-28 |
案例
HOW- 目标
- negotiate HTTP Accept header content type using goautoneg
- 符号
-
- Negotiate
- ParseAccept
- 创建时间
- 2026-08-28T00:09:07Z
契约
- Negotiate selects the highest quality media type among available alternatives
- Negotiate resolves wildcards and subtype wildcards according to quality values
- Negotiate returns an empty string when no alternatives match the accept header
- ParseAccept parses media types, quality values, and parameters into ordered clauses
- ParseAccept parses wildcard media types with quality parameters
文件
- 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: negotiate HTTP Accept header content type using goautoneg
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/munnerz/goautoneg@v0.0.0-20191010083416-a7dc8b61c822
Demonstrate these symbols/APIs:
- Negotiate
- ParseAccept
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:cb77f3449f65beed108e56c17674e85655f85fe81ce457057062e98f63d1adf5","contract":["Negotiate selects the highest quality media type among available alternatives","Negotiate resolves wildcards and subtype wildcards according to quality values","Negotiate returns an empty string when no alternatives match the accept header","ParseAccept parses media types, quality values, and parameters into ordered clauses","ParseAccept parses wildcard media types with quality parameters"],"goal":"negotiate HTTP Accept header content type using goautoneg","kind":"HOW","packages":["pkg:golang/github.com/munnerz/goautoneg@v0.0.0-20191010083416-a7dc8b61c822"],"schemaVersion":1,"symbols":["Negotiate","ParseAccept"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/munnerz/goautoneg@v0.0.0-20191010083416-a7dc8b61c822"],"schemaVersion":1,"subject":"pkg:golang/github.com/munnerz/goautoneg@v0.0.0-20191010083416-a7dc8b61c822","symbols":["Negotiate","ParseAccept"],"verifierAdapter":"golang@1"}
module sample
go 1.26.6
require github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
package main
import (
"fmt"
"github.com/munnerz/goautoneg"
)
func main() {
header := "text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8"
alternatives := []string{"application/json", "text/html", "application/xml"}
selected := goautoneg.Negotiate(header, alternatives)
fmt.Printf("Negotiated content type: %s\n", selected)
clauses := goautoneg.ParseAccept(header)
fmt.Printf("Parsed %d clauses\n", len(clauses))
}
{
"schemaVersion": 1,
"goal": "negotiate HTTP Accept header content type using goautoneg",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/munnerz/goautoneg@v0.0.0-20191010083416-a7dc8b61c822"
],
"symbols": [
"Negotiate",
"ParseAccept"
]
}
package main
import (
"fmt"
"math"
"os"
"github.com/munnerz/goautoneg"
)
func main() {
if err := runContract(); err != nil {
fmt.Fprintf(os.Stderr, "Contract verification failed: %v\n", err)
os.Exit(1)
}
fmt.Println("All goautoneg contract assertions passed successfully.")
}
func runContract() error {
// Assertion 1: Negotiate selects the highest quality media type among available alternatives
header1 := "text/plain;q=0.5, application/json;q=0.9, text/html;q=0.8"
alts1 := []string{"text/plain", "application/json", "text/html"}
if got := goautoneg.Negotiate(header1, alts1); got != "application/json" {
return fmt.Errorf("assertion 1 failed: expected %q, got %q", "application/json", got)
}
// Assertion 2: Negotiate resolves wildcards and subtype wildcards according to quality values
header2 := "image/*;q=0.8, text/*;q=0.6, */*;q=0.1"
alts2 := []string{"application/pdf", "image/png", "text/plain"}
if got := goautoneg.Negotiate(header2, alts2); got != "image/png" {
return fmt.Errorf("assertion 2 failed: expected %q, got %q", "image/png", got)
}
// Assertion 3: Negotiate returns an empty string when no alternatives match the accept header
header3 := "application/json, application/xml"
alts3 := []string{"image/png", "text/html"}
if got := goautoneg.Negotiate(header3, alts3); got != "" {
return fmt.Errorf("assertion 3 failed: expected empty string, got %q", got)
}
// Assertion 4: ParseAccept parses media types, quality values, and parameters into ordered clauses
header4 := "text/html;level=1;q=0.7, application/json;q=1.0, text/plain;q=0.5"
clauses := goautoneg.ParseAccept(header4)
if len(clauses) != 3 {
return fmt.Errorf("assertion 4 failed: expected 3 clauses, got %d", len(clauses))
}
if clauses[0].Type != "application" || clauses[0].SubType != "json" || math.Abs(clauses[0].Q-1.0) > 1e-4 {
return fmt.Errorf("assertion 4 failed: clause 0 mismatch: %+v", clauses[0])
}
if clauses[1].Type != "text" || clauses[1].SubType != "html" || math.Abs(clauses[1].Q-0.7) > 1e-4 || clauses[1].Params["level"] != "1" {
return fmt.Errorf("assertion 4 failed: clause 1 mismatch: %+v", clauses[1])
}
if clauses[2].Type != "text" || clauses[2].SubType != "plain" || math.Abs(clauses[2].Q-0.5) > 1e-4 {
return fmt.Errorf("assertion 4 failed: clause 2 mismatch: %+v", clauses[2])
}
// Assertion 5: ParseAccept parses wildcard media types with quality parameters
header5 := "*/*;q=0.2"
clauses5 := goautoneg.ParseAccept(header5)
if len(clauses5) != 1 {
return fmt.Errorf("assertion 5 failed: expected 1 clause, got %d", len(clauses5))
}
if clauses5[0].Type != "*" || clauses5[0].SubType != "*" || math.Abs(clauses5[0].Q-0.2) > 1e-4 {
return fmt.Errorf("assertion 5 failed: clause mismatch: %+v", clauses5[0])
}
return nil
}
原始种子者
匿名