Exemplo
golang.org/x/time v0.15.0: rate.NewLimiter
Amostra verificada para golang golang.org/x/time v0.15.0: rate.NewLimiter. O contrato rodou em go 1.26 · linux debian/x64 · docker e passou.
sha256:bef202d6efac0427386c8b2eadce8b74dfe8b38499d6ce9c56de03f99d4f0eab
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
linux 24 · ubuntu · glibc 2.39 x64 go
Ambientes das execuções de verificação
| Ambiente | Contrato | Etapas | Execução |
|---|---|---|---|
| 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-01 |
Caso
HOW- Objetivo
- verify rate.NewLimiter in pkg:golang/golang.org/x/time@v0.15.0
- Pacotes
- Símbolos
-
- rate.NewLimiter
- Criado
- 2026-09-01T10:44:19Z
Contrato
- rate.NewLimiter creates a token bucket limiter with specified rate and burst size
- rate.NewLimiter allows events up to burst size immediately
- rate.NewLimiter accepts rate.Every and rate.Inf
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 rate.NewLimiter in pkg:golang/golang.org/x/time@v0.15.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/time@v0.15.0
Demonstrate these symbols/APIs:
- rate.NewLimiter
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:6688c967d12875a6f055af65b73e4ea72cb6364a0ca65ca548ec1d7c4ba7d9fe","contract":["rate.NewLimiter creates a token bucket limiter with specified rate and burst size","rate.NewLimiter allows events up to burst size immediately","rate.NewLimiter accepts rate.Every and rate.Inf"],"goal":"verify rate.NewLimiter in pkg:golang/golang.org/x/time@v0.15.0","kind":"HOW","packages":["pkg:golang/golang.org/x/time@v0.15.0"],"schemaVersion":1,"symbols":["rate.NewLimiter"]},"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/golang.org/x/time@v0.15.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/time@v0.15.0","symbols":["rate.NewLimiter"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.25.0
require golang.org/x/time v0.15.0
golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U=
golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno=
package main
import (
"context"
"fmt"
"time"
"golang.org/x/time/rate"
)
func main() {
// Create a rate limiter that allows 5 events per second with a burst of 2.
limiter := rate.NewLimiter(rate.Limit(5), 2)
fmt.Printf("Rate limit: %v events/sec, burst size: %d\n", limiter.Limit(), limiter.Burst())
// Consume the initial burst
for i := 1; i <= 2; i++ {
if limiter.Allow() {
fmt.Printf("Event %d allowed immediately\n", i)
}
}
// Next event exceeds burst
if !limiter.Allow() {
fmt.Println("Event 3 rate-limited as expected")
}
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
defer cancel()
if err := limiter.Wait(ctx); err == nil {
fmt.Println("Event 4 allowed after waiting for token replenishment")
}
}
{
"schemaVersion": 1,
"goal": "verify rate.NewLimiter in pkg:golang/golang.org/x/time@v0.15.0",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/time@v0.15.0"
],
"symbols": [
"rate.NewLimiter"
]
}
package main
import (
"fmt"
"math"
"os"
"time"
"golang.org/x/time/rate"
)
func main() {
// 1. rate.NewLimiter creates a token bucket limiter with specified rate and burst size
lim := rate.NewLimiter(rate.Limit(10), 3)
if lim.Limit() != rate.Limit(10) {
fmt.Fprintf(os.Stderr, "Contract assertion failed: Limit() got %v, want 10\n", lim.Limit())
os.Exit(1)
}
if lim.Burst() != 3 {
fmt.Fprintf(os.Stderr, "Contract assertion failed: Burst() got %d, want 3\n", lim.Burst())
os.Exit(1)
}
// 2. rate.NewLimiter allows events up to burst size immediately
// Bucket starts full with 3 tokens
for i := 0; i < 3; i++ {
if !lim.Allow() {
fmt.Fprintf(os.Stderr, "Contract assertion failed: Allow() returned false within burst capacity at iteration %d\n", i+1)
os.Exit(1)
}
}
// 4th event exceeds burst capacity when called immediately
if lim.Allow() {
fmt.Fprintf(os.Stderr, "Contract assertion failed: Allow() returned true when burst was exhausted\n")
os.Exit(1)
}
// 3. rate.NewLimiter accepts rate.Every and rate.Inf
everyLim := rate.NewLimiter(rate.Every(100*time.Millisecond), 1)
if math.Abs(float64(everyLim.Limit())-10.0) > 1e-6 {
fmt.Fprintf(os.Stderr, "Contract assertion failed: rate.Every(100ms) limit got %v, want 10\n", everyLim.Limit())
os.Exit(1)
}
infLim := rate.NewLimiter(rate.Inf, 0)
if infLim.Limit() != rate.Inf {
fmt.Fprintf(os.Stderr, "Contract assertion failed: rate.Inf limit got %v, want Inf\n", infLim.Limit())
os.Exit(1)
}
if !infLim.Allow() {
fmt.Fprintf(os.Stderr, "Contract assertion failed: rate.Inf Allow() returned false\n")
os.Exit(1)
}
fmt.Println("All contract assertions passed.")
}
Seeder de origem
anônimo