샘플
github.com/go-logfmt/logfmt v0.5.0: MarshalKeyvals
검증된 샘플 — golang github.com/go-logfmt/logfmt v0.5.0: MarshalKeyvals. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다.
sha256:6fb4245f53e54918d051b0dea910fe3bed11182fcdba921769a854db176c03cb
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
linux 24 · ubuntu · glibc 2.39 x64 go
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| 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-03 |
케이스
HOW- 목표
- verify pkg:golang/github.com/go-logfmt/logfmt@v0.5.0
- 심벌
-
- github.com/go-logfmt/logfmt.MarshalKeyvals
- 생성일
- 2026-09-03T18:52:25Z
컨트랙트
- logfmt.MarshalKeyvals serializes variadic key-value pairs into logfmt format without trailing newline
- logfmt.MarshalKeyvals correctly formats and quotes values containing spaces, quotes, and newlines
- logfmt.MarshalKeyvals formats types including booleans, errors, time.Time, and fmt.Stringer
- logfmt.MarshalKeyvals returns ErrNilKey when a nil key is provided
- logfmt.MarshalKeyvals returns ErrInvalidKey when a key contains only invalid runes like spaces or equals
- logfmt.MarshalKeyvals handles odd number of arguments by appending null value
- Helper functions in sample package format key-value pairs accurately
파일
- PROMPT.md
- csx.json
- go.mod
- go.sum
- sample.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 pkg:golang/github.com/go-logfmt/logfmt@v0.5.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/go-logfmt/logfmt@v0.5.0
Demonstrate these symbols/APIs:
- github.com/go-logfmt/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.
{"case":{"caseId":"case:sha256:45042ec20eeef6b1c3c9006f3d38002eec0d0565b0a64e73728fe92aeba3fcf1","contract":["logfmt.MarshalKeyvals serializes variadic key-value pairs into logfmt format without trailing newline","logfmt.MarshalKeyvals correctly formats and quotes values containing spaces, quotes, and newlines","logfmt.MarshalKeyvals formats types including booleans, errors, time.Time, and fmt.Stringer","logfmt.MarshalKeyvals returns ErrNilKey when a nil key is provided","logfmt.MarshalKeyvals returns ErrInvalidKey when a key contains only invalid runes like spaces or equals","logfmt.MarshalKeyvals handles odd number of arguments by appending null value","Helper functions in sample package format key-value pairs accurately"],"goal":"verify pkg:golang/github.com/go-logfmt/logfmt@v0.5.0","kind":"HOW","packages":["pkg:golang/github.com/go-logfmt/logfmt@v0.5.0"],"schemaVersion":1,"symbols":["github.com/go-logfmt/logfmt.MarshalKeyvals"]},"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/go-logfmt/logfmt@v0.5.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/go-logfmt/logfmt@v0.5.0","symbols":["github.com/go-logfmt/logfmt.MarshalKeyvals"],"verifierAdapter":"golang@1"}
module sample
go 1.26.6
require github.com/go-logfmt/logfmt v0.5.0
github.com/go-logfmt/logfmt v0.5.0 h1:TrB8swr/68K7m9CcGut2g3UOihhbcbiMAYiuTXdEih4=
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
package sample
import (
"github.com/go-logfmt/logfmt"
)
// FormatLog formats alternating key-value pairs into a logfmt byte slice.
func FormatLog(keyvals ...interface{}) ([]byte, error) {
return logfmt.MarshalKeyvals(keyvals...)
}
// FormatLogString formats alternating key-value pairs into a logfmt string.
func FormatLogString(keyvals ...interface{}) (string, error) {
b, err := logfmt.MarshalKeyvals(keyvals...)
if err != nil {
return "", err
}
return string(b), nil
}
{
"schemaVersion": 1,
"goal": "verify pkg:golang/github.com/go-logfmt/logfmt@v0.5.0",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/go-logfmt/logfmt@v0.5.0"
],
"symbols": [
"github.com/go-logfmt/logfmt.MarshalKeyvals"
]
}
package main
import (
"bytes"
"errors"
"fmt"
"os"
"strings"
"time"
"github.com/go-logfmt/logfmt"
"sample"
)
type customStringer struct {
val string
}
func (c customStringer) String() string {
return c.val
}
func main() {
// Assertion 1: logfmt.MarshalKeyvals serializes variadic key-value pairs into logfmt format without trailing newline
b1, err := logfmt.MarshalKeyvals("level", "info", "app", "demo", "count", 42)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 1 error: %v\n", err)
os.Exit(1)
}
expected1 := "level=info app=demo count=42"
if string(b1) != expected1 {
fmt.Fprintf(os.Stderr, "assertion 1 mismatch: got %q, expected %q\n", string(b1), expected1)
os.Exit(1)
}
if bytes.HasSuffix(b1, []byte("\n")) {
fmt.Fprintf(os.Stderr, "assertion 1 failed: MarshalKeyvals should not append a trailing newline\n")
os.Exit(1)
}
// Assertion 2: logfmt.MarshalKeyvals correctly formats and quotes values containing spaces, quotes, and newlines
b2, err := logfmt.MarshalKeyvals("msg", "hello world", "quote", `quoted "value"`, "newline", "line1\nline2")
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 2 error: %v\n", err)
os.Exit(1)
}
got2 := string(b2)
if !strings.Contains(got2, `msg="hello world"`) {
fmt.Fprintf(os.Stderr, "assertion 2 failed: expected quoted spaces in msg, got %q\n", got2)
os.Exit(1)
}
if !strings.Contains(got2, `quote="quoted \"value\""`) {
fmt.Fprintf(os.Stderr, "assertion 2 failed: expected escaped quotes, got %q\n", got2)
os.Exit(1)
}
// Assertion 3: logfmt.MarshalKeyvals formats types including booleans, errors, time.Time, and fmt.Stringer
ts := time.Date(2026, 8, 27, 12, 0, 0, 0, time.UTC)
testErr := errors.New("connection reset")
stringer := customStringer{val: "custom-val"}
b3, err := logfmt.MarshalKeyvals("time", ts, "active", true, "err", testErr, "custom", stringer)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 3 error: %v\n", err)
os.Exit(1)
}
got3 := string(b3)
expected3 := "time=2026-08-27T12:00:00Z active=true err=\"connection reset\" custom=custom-val"
if got3 != expected3 {
fmt.Fprintf(os.Stderr, "assertion 3 mismatch: got %q, expected %q\n", got3, expected3)
os.Exit(1)
}
// Assertion 4: logfmt.MarshalKeyvals returns ErrNilKey when a nil key is provided
_, errNil := logfmt.MarshalKeyvals(nil, "value")
if !errors.Is(errNil, logfmt.ErrNilKey) {
fmt.Fprintf(os.Stderr, "assertion 4 failed: expected ErrNilKey, got %v\n", errNil)
os.Exit(1)
}
// Assertion 5: logfmt.MarshalKeyvals returns ErrInvalidKey when a key contains only invalid runes like spaces or equals
_, errInvalid := logfmt.MarshalKeyvals(" ", "value")
if !errors.Is(errInvalid, logfmt.ErrInvalidKey) {
fmt.Fprintf(os.Stderr, "assertion 5 failed: expected ErrInvalidKey for whitespace key, got %v\n", errInvalid)
os.Exit(1)
}
_, errInvalidEq := logfmt.MarshalKeyvals("=", "value")
if !errors.Is(errInvalidEq, logfmt.ErrInvalidKey) {
fmt.Fprintf(os.Stderr, "assertion 5 failed: expected ErrInvalidKey for equals key, got %v\n", errInvalidEq)
os.Exit(1)
}
// Assertion 6: logfmt.MarshalKeyvals handles odd number of arguments by appending null value
bOdd, errOdd := logfmt.MarshalKeyvals("key1", "val1", "key2")
if errOdd != nil {
fmt.Fprintf(os.Stderr, "assertion 6 failed with error: %v\n", errOdd)
os.Exit(1)
}
if string(bOdd) != "key1=val1 key2=null" {
fmt.Fprintf(os.Stderr, "assertion 6 mismatch: got %q, expected %q\n", string(bOdd), "key1=val1 key2=null")
os.Exit(1)
}
// Assertion 7: Helper functions in sample package format key-value pairs accurately
bHelper, err := sample.FormatLog("env", "production", "status", 200)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 7 FormatLog error: %v\n", err)
os.Exit(1)
}
if string(bHelper) != "env=production status=200" {
fmt.Fprintf(os.Stderr, "assertion 7 FormatLog mismatch: got %q\n", string(bHelper))
os.Exit(1)
}
sHelper, err := sample.FormatLogString("env", "production", "status", 200)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 7 FormatLogString error: %v\n", err)
os.Exit(1)
}
if sHelper != "env=production status=200" {
fmt.Fprintf(os.Stderr, "assertion 7 FormatLogString mismatch: got %q\n", sHelper)
os.Exit(1)
}
fmt.Println("All contract assertions passed.")
}
오리진 시더
익명