샘플
github.com/go-logfmt/logfmt v0.5.0: Encoder.EncodeKeyval
검증된 샘플 — golang github.com/go-logfmt/logfmt v0.5.0: Encoder.EncodeKeyval. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다.
sha256:c7be55960872d3f3417f8558b68b7a063b809b8e00f118bd1d3fa7dd888475d8
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
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.Encoder.EncodeKeyval
- 생성일
- 2026-09-03T18:59:18Z
컨트랙트
- logfmt.Encoder.EncodeKeyval writes the logfmt encoding of a single key and value to the output stream
- logfmt.Encoder.EncodeKeyval writes a single space separator before second and subsequent key-value pairs on the same record
- logfmt.Encoder.EncodeKeyval formats nil values as null
- logfmt.Encoder.EncodeKeyval returns ErrNilKey on nil key or nil pointer and writes nothing to the stream
- logfmt.Encoder.EncodeKeyval returns ErrInvalidKey when key contains only invalid runes and writes nothing to the stream
- logfmt.Encoder.EncodeKeyval returns ErrUnsupportedKeyType for array chan func map slice or struct key and writes nothing to the stream
- logfmt.Encoder.EncodeKeyval returns ErrUnsupportedValueType for unsupported complex types and writes nothing to the stream
파일
- 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.Encoder.EncodeKeyval
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:abbe8b8081550de2c538216831908649ccb2947490e0f1de52694c076fbd09bc","contract":["logfmt.Encoder.EncodeKeyval writes the logfmt encoding of a single key and value to the output stream","logfmt.Encoder.EncodeKeyval writes a single space separator before second and subsequent key-value pairs on the same record","logfmt.Encoder.EncodeKeyval formats nil values as null","logfmt.Encoder.EncodeKeyval returns ErrNilKey on nil key or nil pointer and writes nothing to the stream","logfmt.Encoder.EncodeKeyval returns ErrInvalidKey when key contains only invalid runes and writes nothing to the stream","logfmt.Encoder.EncodeKeyval returns ErrUnsupportedKeyType for array chan func map slice or struct key and writes nothing to the stream","logfmt.Encoder.EncodeKeyval returns ErrUnsupportedValueType for unsupported complex types and writes nothing to the stream"],"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.Encoder.EncodeKeyval"]},"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.Encoder.EncodeKeyval"],"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 (
"bytes"
"io"
"github.com/go-logfmt/logfmt"
)
// LogEntry writes key-value pairs one by one using EncodeKeyval and ends the record with a newline.
func LogEntry(w io.Writer, kvs [][2]interface{}) error {
enc := logfmt.NewEncoder(w)
for _, kv := range kvs {
if err := enc.EncodeKeyval(kv[0], kv[1]); err != nil {
return err
}
}
return enc.EndRecord()
}
// FormatPair encodes a single key-value pair to a string using EncodeKeyval.
func FormatPair(key, value interface{}) (string, error) {
var buf bytes.Buffer
enc := logfmt.NewEncoder(&buf)
if err := enc.EncodeKeyval(key, value); err != nil {
return "", err
}
return buf.String(), 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.Encoder.EncodeKeyval"
]
}
package main
import (
"bytes"
"errors"
"fmt"
"os"
"github.com/go-logfmt/logfmt"
"sample"
)
func main() {
// Assertion 1: logfmt.Encoder.EncodeKeyval writes the logfmt encoding of a single key and value to the output stream
var buf bytes.Buffer
enc := logfmt.NewEncoder(&buf)
if err := enc.EncodeKeyval("msg", "hello world"); err != nil {
fmt.Fprintf(os.Stderr, "Assertion 1 failed: %v\n", err)
os.Exit(1)
}
if buf.String() != "msg=\"hello world\"" {
fmt.Fprintf(os.Stderr, "Assertion 1 output mismatch: %q\n", buf.String())
os.Exit(1)
}
// Assertion 2: logfmt.Encoder.EncodeKeyval writes a single space separator before second and subsequent key-value pairs on the same record
if err := enc.EncodeKeyval("count", 42); err != nil {
fmt.Fprintf(os.Stderr, "Assertion 2 failed: %v\n", err)
os.Exit(1)
}
if buf.String() != "msg=\"hello world\" count=42" {
fmt.Fprintf(os.Stderr, "Assertion 2 output mismatch: %q\n", buf.String())
os.Exit(1)
}
if err := enc.EndRecord(); err != nil {
fmt.Fprintf(os.Stderr, "EndRecord failed: %v\n", err)
os.Exit(1)
}
if buf.String() != "msg=\"hello world\" count=42\n" {
fmt.Fprintf(os.Stderr, "EndRecord output mismatch: %q\n", buf.String())
os.Exit(1)
}
// Assertion 3: logfmt.Encoder.EncodeKeyval formats nil values as null
buf.Reset()
if err := enc.EncodeKeyval("data", nil); err != nil {
fmt.Fprintf(os.Stderr, "Assertion 3 failed: %v\n", err)
os.Exit(1)
}
if buf.String() != "data=null" {
fmt.Fprintf(os.Stderr, "Assertion 3 output mismatch: %q\n", buf.String())
os.Exit(1)
}
// Assertion 4: logfmt.Encoder.EncodeKeyval returns ErrNilKey on nil key or nil pointer and writes nothing to the stream
buf.Reset()
if err := enc.EncodeKeyval(nil, "val"); !errors.Is(err, logfmt.ErrNilKey) {
fmt.Fprintf(os.Stderr, "Assertion 4 nil interface failed: expected ErrNilKey, got %v\n", err)
os.Exit(1)
}
var nilPtr *string
if err := enc.EncodeKeyval(nilPtr, "val"); !errors.Is(err, logfmt.ErrNilKey) {
fmt.Fprintf(os.Stderr, "Assertion 4 nil pointer failed: expected ErrNilKey, got %v\n", err)
os.Exit(1)
}
if buf.Len() != 0 {
fmt.Fprintf(os.Stderr, "Assertion 4 stream mismatch: expected empty buffer, got %q\n", buf.String())
os.Exit(1)
}
// Assertion 5: logfmt.Encoder.EncodeKeyval returns ErrInvalidKey when key contains only invalid runes and writes nothing to the stream
buf.Reset()
if err := enc.EncodeKeyval(" ===", "val"); !errors.Is(err, logfmt.ErrInvalidKey) {
fmt.Fprintf(os.Stderr, "Assertion 5 failed: expected ErrInvalidKey, got %v\n", err)
os.Exit(1)
}
if buf.Len() != 0 {
fmt.Fprintf(os.Stderr, "Assertion 5 stream mismatch: expected empty buffer, got %q\n", buf.String())
os.Exit(1)
}
// Assertion 6: logfmt.Encoder.EncodeKeyval returns ErrUnsupportedKeyType for array chan func map slice or struct key and writes nothing to the stream
buf.Reset()
type dummyKey struct{}
if err := enc.EncodeKeyval(dummyKey{}, "val"); !errors.Is(err, logfmt.ErrUnsupportedKeyType) {
fmt.Fprintf(os.Stderr, "Assertion 6 failed: expected ErrUnsupportedKeyType, got %v\n", err)
os.Exit(1)
}
if buf.Len() != 0 {
fmt.Fprintf(os.Stderr, "Assertion 6 stream mismatch: expected empty buffer, got %q\n", buf.String())
os.Exit(1)
}
// Assertion 7: logfmt.Encoder.EncodeKeyval returns ErrUnsupportedValueType for unsupported complex types and writes nothing to the stream
buf.Reset()
type dummyVal struct{}
if err := enc.EncodeKeyval("meta", dummyVal{}); !errors.Is(err, logfmt.ErrUnsupportedValueType) {
fmt.Fprintf(os.Stderr, "Assertion 7 failed: expected ErrUnsupportedValueType, got %v\n", err)
os.Exit(1)
}
if buf.Len() != 0 {
fmt.Fprintf(os.Stderr, "Assertion 7 stream mismatch: expected empty buffer, got %q\n", buf.String())
os.Exit(1)
}
// Helper verification: LogEntry and FormatPair
pairStr, err := sample.FormatPair("status", "ok")
if err != nil || pairStr != "status=ok" {
fmt.Fprintf(os.Stderr, "FormatPair helper failed: %v, got %q\n", err, pairStr)
os.Exit(1)
}
buf.Reset()
err = sample.LogEntry(&buf, [][2]interface{}{
{"module", "auth"},
{"action", "login"},
})
if err != nil || buf.String() != "module=auth action=login\n" {
fmt.Fprintf(os.Stderr, "LogEntry helper failed: %v, got %q\n", err, buf.String())
os.Exit(1)
}
fmt.Println("All contract assertions passed.")
}
오리진 시더
익명