Exemplo
github.com/go-kit/kit v0.4.0: log.Logger, log.NewJSONLogger, log.NewLogfmtLogger
Amostra verificada para golang github.com/go-kit/kit v0.4.0: log.Logger, log.NewJSONLogger, log.NewLogfmtLogger. O contrato rodou em go 1.26 · linux…
sha256:ccfa30ac66db1800a090be76da5438f5cf1aa4ba5061ca6ff5040edced5b7b6a
Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu.
Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas.
MIT-0
Evidência de execução
O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.
- Base da evidência
- Contrato assinado aprovado
- Recibos de verificação
- 1
- Chaves de assinatura que o compilaram
- 1
Ambiente declarado
go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1
Ambientes das execuções de verificação
| Ambiente | Contrato | Etapas | Execução |
|---|---|---|---|
| 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 |
Caso
HOW- Objetivo
- verify pkg:golang/github.com/go-kit/kit@v0.4.0
- Pacotes
- Símbolos
-
- log.Logger
- log.NewJSONLogger
- log.NewLogfmtLogger
- log.Valuer
- log.With
- Ambiente
- go 1.26.6
- Criado
- 2026-08-28T09:38:48Z
Contrato
- log.NewLogfmtLogger writes key-value pairs in logfmt format separated by spaces with newline termination
- log.With prepends contextual key-value pairs and evaluates log.Valuer dynamically on each Log invocation
- log.NewJSONLogger encodes structured key-value pairs into valid JSON objects with typed primitives
Arquivos
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Código-fonte
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-kit/kit@v0.4.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/go-kit/kit@v0.4.0
Required runtime conditions:
- ecosystem: golang
- language: go
- packageManager: go@1.26.6
- runtime: go@1.26.6
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:b2c61ff9d1a682ab78bc3112267f8680fe150aae930e6de322d4a2afb5734658","contract":["log.NewLogfmtLogger writes key-value pairs in logfmt format separated by spaces with newline termination","log.With prepends contextual key-value pairs and evaluates log.Valuer dynamically on each Log invocation","log.NewJSONLogger encodes structured key-value pairs into valid JSON objects with typed primitives"],"goal":"verify pkg:golang/github.com/go-kit/kit@v0.4.0","kind":"HOW","packages":["pkg:golang/github.com/go-kit/kit@v0.4.0"],"schemaVersion":1,"symbols":["log.Logger","log.NewJSONLogger","log.NewLogfmtLogger","log.Valuer","log.With"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","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-kit/kit@v0.4.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/go-kit/kit@v0.4.0","symbols":["log.Logger","log.NewJSONLogger","log.NewLogfmtLogger","log.Valuer","log.With"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.22
require github.com/go-kit/kit v0.4.0
require (
github.com/go-logfmt/logfmt v0.6.1 // indirect
github.com/go-stack/stack v1.8.1 // indirect
)
github.com/go-kit/kit v0.4.0 h1:KeVK+Emj3c3S4eRztFuzbFYb2BAgf2jmwDwyXEri7Lo=
github.com/go-kit/kit v0.4.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.6.1 h1:4hvbpePJKnIzH1B+8OR/JPbTx37NktoI9LE2QZBBkvE=
github.com/go-logfmt/logfmt v0.6.1/go.mod h1:EV2pOAQoZaT1ZXZbqDl5hrymndi4SY9ED9/z6CO0XAk=
github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw=
github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
package main
import (
"bytes"
"fmt"
"sync/atomic"
"github.com/go-kit/kit/log"
)
func main() {
// 1. Create a logfmt logger writing to a buffer
var logfmtBuf bytes.Buffer
logger := log.NewLogfmtLogger(&logfmtBuf)
// Decorate logger with contextual fields (static component and dynamic request counter)
var reqCount int64
contextLogger := log.With(
logger,
"component", "service-handler",
"req_id", log.Valuer(func() interface{} {
return atomic.AddInt64(&reqCount, 1)
}),
)
// Log events using the contextual logger
_ = contextLogger.Log("event", "processing_request", "path", "/api/v1/resource")
_ = contextLogger.Log("event", "request_complete", "status", 200)
fmt.Println("--- Logfmt Output ---")
fmt.Print(logfmtBuf.String())
// 2. Create a JSON logger writing to a buffer
var jsonBuf bytes.Buffer
jsonLogger := log.NewJSONLogger(&jsonBuf)
jsonLogger = log.With(jsonLogger, "app", "sample-app")
_ = jsonLogger.Log("msg", "application started", "port", 8080)
_ = jsonLogger.Log("msg", "health check ok", "healthy", true)
fmt.Println("--- JSON Output ---")
fmt.Print(jsonBuf.String())
}
{
"schemaVersion": 1,
"goal": "verify pkg:golang/github.com/go-kit/kit@v0.4.0",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/go-kit/kit@v0.4.0"
],
"symbols": [
"log.Logger",
"log.NewJSONLogger",
"log.NewLogfmtLogger",
"log.Valuer",
"log.With"
],
"runtimeConditions": {
"ecosystem": "golang",
"language": "go",
"packageManager": "go@1.26.6",
"runtime": "go@1.26.6"
}
}
package main
import (
"bytes"
"encoding/json"
"fmt"
"os"
"reflect"
"sync/atomic"
"github.com/go-kit/kit/log"
)
func main() {
// Assertion 1: log.NewLogfmtLogger writes key-value pairs in logfmt format separated by spaces with newline termination
{
var buf bytes.Buffer
logger := log.NewLogfmtLogger(&buf)
if err := logger.Log("key1", "value1", "key2", "value2"); err != nil {
fmt.Fprintf(os.Stderr, "assertion 1 failed: %v\n", err)
os.Exit(1)
}
expected1 := "key1=value1 key2=value2\n"
if buf.String() != expected1 {
fmt.Fprintf(os.Stderr, "assertion 1 failed: expected %q, got %q\n", expected1, buf.String())
os.Exit(1)
}
buf.Reset()
if err := logger.Log("msg", "hello world"); err != nil {
fmt.Fprintf(os.Stderr, "assertion 1 failed: %v\n", err)
os.Exit(1)
}
expectedQuoted := "msg=\"hello world\"\n"
if buf.String() != expectedQuoted {
fmt.Fprintf(os.Stderr, "assertion 1 failed: expected quoted %q, got %q\n", expectedQuoted, buf.String())
os.Exit(1)
}
}
// Assertion 2: log.With prepends contextual key-value pairs and evaluates log.Valuer dynamically on each Log invocation
{
var buf bytes.Buffer
baseLogger := log.NewLogfmtLogger(&buf)
var counter int64
dynamicValuer := log.Valuer(func() interface{} {
return atomic.AddInt64(&counter, 1)
})
contextLogger := log.With(baseLogger, "component", "auth", "seq", dynamicValuer)
if err := contextLogger.Log("action", "login", "user", "alice"); err != nil {
fmt.Fprintf(os.Stderr, "assertion 2 failed: %v\n", err)
os.Exit(1)
}
line1 := buf.String()
expectedLine1 := "component=auth seq=1 action=login user=alice\n"
if line1 != expectedLine1 {
fmt.Fprintf(os.Stderr, "assertion 2 failed: expected line 1 %q, got %q\n", expectedLine1, line1)
os.Exit(1)
}
buf.Reset()
if err := contextLogger.Log("action", "logout", "user", "alice"); err != nil {
fmt.Fprintf(os.Stderr, "assertion 2 failed: %v\n", err)
os.Exit(1)
}
line2 := buf.String()
expectedLine2 := "component=auth seq=2 action=logout user=alice\n"
if line2 != expectedLine2 {
fmt.Fprintf(os.Stderr, "assertion 2 failed: expected line 2 %q, got %q\n", expectedLine2, line2)
os.Exit(1)
}
if counter != 2 {
fmt.Fprintf(os.Stderr, "assertion 2 failed: expected counter 2, got %d\n", counter)
os.Exit(1)
}
}
// Assertion 3: log.NewJSONLogger encodes structured key-value pairs into valid JSON objects with typed primitives
{
var buf bytes.Buffer
jsonLogger := log.NewJSONLogger(&buf)
contextJSON := log.With(jsonLogger, "app", "sample-service")
if err := contextJSON.Log("event", "audit", "status_code", 200, "success", true); err != nil {
fmt.Fprintf(os.Stderr, "assertion 3 failed: %v\n", err)
os.Exit(1)
}
var parsed map[string]interface{}
if err := json.Unmarshal(buf.Bytes(), &parsed); err != nil {
fmt.Fprintf(os.Stderr, "assertion 3 failed: invalid json %q: %v\n", buf.String(), err)
os.Exit(1)
}
expectedParsed := map[string]interface{}{
"app": "sample-service",
"event": "audit",
"status_code": float64(200),
"success": true,
}
if !reflect.DeepEqual(parsed, expectedParsed) {
fmt.Fprintf(os.Stderr, "assertion 3 failed: expected map %v, got %v\n", expectedParsed, parsed)
os.Exit(1)
}
}
fmt.Println("All contract assertions passed.")
}
Seeder de origem
anônimo