サンプル
github.com/go-logfmt/logfmt v0.6.0: MarshalKeyvals
検証済みサンプル — golang github.com/go-logfmt/logfmt v0.6.0: MarshalKeyvals. go 1.26 · linux debian/x64 · docker で contract を実行し、成功しました.
sha256:ee05189aefb62b07f0d1f354f99c3d41242f54e0fd6417c54f7e9ed310d8aeb6
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
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-02 |
ケース
HOW- ゴール
- verify logfmt.MarshalKeyvals in pkg:golang/github.com/go-logfmt/logfmt@v0.6.0
- シンボル
-
- logfmt.MarshalKeyvals
- 環境
- go 1.26.6
- 作成日
- 2026-09-02T01:50:00Z
コントラクト
- logfmt.MarshalKeyvals encodes alternating key-value pairs into logfmt format
- logfmt.MarshalKeyvals quotes string values containing whitespace and escapes inner quotes
- logfmt.MarshalKeyvals encodes empty string values as key= without quotes
- logfmt.MarshalKeyvals encodes nil values and trailing odd keys as key=null
- logfmt.MarshalKeyvals formats fmt.Stringer and error values and fmt.Stringer keys
- logfmt.MarshalKeyvals strips invalid characters from keys
- logfmt.MarshalKeyvals returns logfmt.ErrNilKey when nil key is provided
ファイル
- PROMPT.md
- contract_test.go
- csx.json
- go.mod
- go.sum
- sample.go
- spec.json
ソース
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 logfmt.MarshalKeyvals in pkg:golang/github.com/go-logfmt/logfmt@v0.6.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/go-logfmt/logfmt@v0.6.0
Demonstrate these symbols/APIs:
- logfmt.MarshalKeyvals
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.
package sample
import (
"errors"
"testing"
"github.com/go-logfmt/logfmt"
)
type stringerType struct {
val string
}
func (s stringerType) String() string {
return s.val
}
func TestContractMarshalKeyvals(t *testing.T) {
// 1. Primitive types serialization
data, err := MarshalKeyValues("msg", "job started", "count", 42, "ratio", 0.95, "active", true)
if err != nil {
t.Fatalf("unexpected error marshaling primitive keyvals: %v", err)
}
expected := `msg="job started" count=42 ratio=0.95 active=true`
if string(data) != expected {
t.Fatalf("expected %q, got %q", expected, string(data))
}
// 2. Value quoting and escaping
data, err = MarshalKeyValues("quote", `hello "world"`)
if err != nil {
t.Fatalf("unexpected error marshaling quoted string: %v", err)
}
expectedQuote := `quote="hello \"world\""`
if string(data) != expectedQuote {
t.Fatalf("expected %q, got %q", expectedQuote, string(data))
}
// 3. Empty string value encodes as key= without quotes
data, err = MarshalKeyValues("empty", "")
if err != nil {
t.Fatalf("unexpected error marshaling empty string: %v", err)
}
if string(data) != "empty=" {
t.Fatalf("expected empty=, got %q", string(data))
}
// 4. Nil value encodes as key=null
data, err = MarshalKeyValues("status", nil)
if err != nil {
t.Fatalf("unexpected error marshaling nil value: %v", err)
}
if string(data) != "status=null" {
t.Fatalf("expected status=null, got %q", string(data))
}
// 5. Odd argument count treats trailing key as key=null
data, err = MarshalKeyValues("standalone")
if err != nil {
t.Fatalf("unexpected error marshaling odd key: %v", err)
}
if string(data) != "standalone=null" {
t.Fatalf("expected standalone=null, got %q", string(data))
}
// 6. fmt.Stringer and error values and keys
data, err = MarshalKeyValues(stringerType{val: "tag"}, stringerType{val: "prod"}, "err", errors.New("timeout reached"))
if err != nil {
t.Fatalf("unexpected error marshaling Stringer and error: %v", err)
}
expectedCustom := `tag=prod err="timeout reached"`
if string(data) != expectedCustom {
t.Fatalf("expected %q, got %q", expectedCustom, string(data))
}
// 7. Invalid characters in keys are stripped
data, err = MarshalKeyValues("key with space", "value", "key=1", "val2")
if err != nil {
t.Fatalf("unexpected error marshaling keys with special chars: %v", err)
}
expectedStripped := "keywithspace=value key1=val2"
if string(data) != expectedStripped {
t.Fatalf("expected %q, got %q", expectedStripped, string(data))
}
// 8. Nil key returns ErrNilKey
_, err = MarshalKeyValues(nil, "value")
if !errors.Is(err, logfmt.ErrNilKey) {
t.Fatalf("expected ErrNilKey for nil key, got %v", err)
}
}
{"case":{"caseId":"case:sha256:da73ca28ac1d74d1e49955ffcc03539b19d014ba61b22c3873fa279c868babea","contract":["logfmt.MarshalKeyvals encodes alternating key-value pairs into logfmt format","logfmt.MarshalKeyvals quotes string values containing whitespace and escapes inner quotes","logfmt.MarshalKeyvals encodes empty string values as key= without quotes","logfmt.MarshalKeyvals encodes nil values and trailing odd keys as key=null","logfmt.MarshalKeyvals formats fmt.Stringer and error values and fmt.Stringer keys","logfmt.MarshalKeyvals strips invalid characters from keys","logfmt.MarshalKeyvals returns logfmt.ErrNilKey when nil key is provided"],"goal":"verify logfmt.MarshalKeyvals in pkg:golang/github.com/go-logfmt/logfmt@v0.6.0","kind":"HOW","packages":["pkg:golang/github.com/go-logfmt/logfmt@v0.6.0"],"schemaVersion":1,"symbols":["logfmt.MarshalKeyvals"]},"contractCommand":["go","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/go-logfmt/logfmt@v0.6.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/go-logfmt/logfmt@v0.6.0","symbols":["logfmt.MarshalKeyvals"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.26.6
require github.com/go-logfmt/logfmt v0.6.0
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
package sample
import (
"github.com/go-logfmt/logfmt"
)
// MarshalKeyValues encodes alternating key-value pairs into logfmt structured format.
func MarshalKeyValues(keyvals ...interface{}) ([]byte, error) {
return logfmt.MarshalKeyvals(keyvals...)
}
{
"schemaVersion": 1,
"goal": "verify logfmt.MarshalKeyvals in pkg:golang/github.com/go-logfmt/logfmt@v0.6.0",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/go-logfmt/logfmt@v0.6.0"
],
"symbols": [
"logfmt.MarshalKeyvals"
]
}
オリジンシーダー
匿名