샘플
golang.org/x/time v0.15.0: rate.Every
검증된 샘플 — golang golang.org/x/time v0.15.0: rate.Every. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: rate.Every(100 * time.Millisecond) returns…
sha256:714578e63a5d4c45b34247c03d4046157e64bb6a08f8cbb8356e4284ca0ddbf3
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
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-01 |
케이스
HOW- 목표
- verify rate.Every in pkg:golang/golang.org/x/time@v0.15.0
- 심벌
-
- rate.Every
- 생성일
- 2026-09-01T10:38:03Z
컨트랙트
- rate.Every(100 * time.Millisecond) returns Limit(10.0)
- rate.Every(1 * time.Second) returns Limit(1.0)
- rate.Every(500 * time.Millisecond) returns Limit(2.0)
- rate.Every(0) returns rate.Inf
- rate.Every(-5 * time.Second) returns rate.Inf
- rate.NewLimiter(rate.Every(200 * time.Millisecond), 3) creates limiter with Limit(5.0) and Burst(3)
- limiter.SetLimit(rate.Every(50 * time.Millisecond)) updates limit to Limit(20.0)
파일
- PROMPT.md
- csx.json
- go.mod
- go.sum
- rate_every.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 rate.Every 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.Every
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:d16c4e4b6caae41e4278f5e5a186d408bf23d658496d5ab18eb9f68a84bbad97","contract":["rate.Every(100 * time.Millisecond) returns Limit(10.0)","rate.Every(1 * time.Second) returns Limit(1.0)","rate.Every(500 * time.Millisecond) returns Limit(2.0)","rate.Every(0) returns rate.Inf","rate.Every(-5 * time.Second) returns rate.Inf","rate.NewLimiter(rate.Every(200 * time.Millisecond), 3) creates limiter with Limit(5.0) and Burst(3)","limiter.SetLimit(rate.Every(50 * time.Millisecond)) updates limit to Limit(20.0)"],"goal":"verify rate.Every 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.Every"]},"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.Every"],"verifierAdapter":"golang@1"}
module example.com/rate-every-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 rateexample
import (
"time"
"golang.org/x/time/rate"
)
// IntervalToLimit converts a minimum duration interval between events to a rate.Limit.
func IntervalToLimit(interval time.Duration) rate.Limit {
return rate.Every(interval)
}
// NewIntervalLimiter creates a new rate.Limiter configured with a per-interval rate and burst size.
func NewIntervalLimiter(interval time.Duration, burst int) *rate.Limiter {
return rate.NewLimiter(rate.Every(interval), burst)
}
{
"schemaVersion": 1,
"goal": "verify rate.Every in pkg:golang/golang.org/x/time@v0.15.0",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/time@v0.15.0"
],
"symbols": [
"rate.Every"
]
}
package main
import (
"fmt"
"math"
"os"
"time"
"golang.org/x/time/rate"
rateexample "example.com/rate-every-sample"
)
func main() {
if err := runContractTests(); err != nil {
fmt.Fprintf(os.Stderr, "Contract test failed: %v\n", err)
os.Exit(1)
}
fmt.Println("All contract assertions passed.")
}
func runContractTests() error {
// Assertion 1: Positive intervals convert to reciprocal frequency (events per second)
// 100ms interval => 10 events/second
l100ms := rateexample.IntervalToLimit(100 * time.Millisecond)
if math.Abs(float64(l100ms)-10.0) > 1e-6 {
return fmt.Errorf("expected 10.0 limit for 100ms, got %v", l100ms)
}
// Assertion 2: 1 second interval => 1 event/second
l1s := rate.Every(1 * time.Second)
if math.Abs(float64(l1s)-1.0) > 1e-6 {
return fmt.Errorf("expected 1.0 limit for 1s, got %v", l1s)
}
// Assertion 3: 500ms interval => 2 events/second
l500ms := rate.Every(500 * time.Millisecond)
if math.Abs(float64(l500ms)-2.0) > 1e-6 {
return fmt.Errorf("expected 2.0 limit for 500ms, got %v", l500ms)
}
// Assertion 4: 0 duration returns rate.Inf (infinite rate, no limit)
l0 := rate.Every(0)
if l0 != rate.Inf {
return fmt.Errorf("expected rate.Inf for 0 duration, got %v", l0)
}
// Assertion 5: Negative duration returns rate.Inf
lNeg := rate.Every(-5 * time.Second)
if lNeg != rate.Inf {
return fmt.Errorf("expected rate.Inf for negative duration, got %v", lNeg)
}
// Assertion 6: rate.NewLimiter with rate.Every sets the expected Limit and Burst
limiter := rateexample.NewIntervalLimiter(200*time.Millisecond, 3)
if limiter.Limit() != rate.Limit(5.0) {
return fmt.Errorf("expected limiter limit 5.0, got %v", limiter.Limit())
}
if limiter.Burst() != 3 {
return fmt.Errorf("expected limiter burst 3, got %d", limiter.Burst())
}
// Assertion 7: Dynamic limit updates with rate.Every
limiter.SetLimit(rate.Every(50 * time.Millisecond))
if math.Abs(float64(limiter.Limit())-20.0) > 1e-6 {
return fmt.Errorf("expected updated limit 20.0, got %v", limiter.Limit())
}
return nil
}
오리진 시더
익명