Sample
github.com/go-logfmt/logfmt v0.5.0: Encoder.EncodeKeyval
Verified sample for golang github.com/go-logfmt/logfmt v0.5.0: Encoder.EncodeKeyval. The contract ran on go 1.26 · linux debian/x64 · docker and passed.
sha256:c7be55960872d3f3417f8558b68b7a063b809b8e00f118bd1d3fa7dd888475d8
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 1
- Signing keys that built it
- 1
Declared environment
linux 24 · ubuntu · glibc 2.39 x64 go
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| 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 |
Case
HOW- Goal
- verify pkg:golang/github.com/go-logfmt/logfmt@v0.5.0
- Packages
- Symbols
-
- github.com/go-logfmt/logfmt.Encoder.EncodeKeyval
- Created
- 2026-09-03T18:59:18Z
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
Files
- PROMPT.md
- csx.json
- go.mod
- go.sum
- sample.go
- spec.json
- test/contract.go
Source
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.")
}
Origin Seeder
anonymous