サンプル
google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5: attribute_context.AttributeContext_Peer
検証済みサンプル — golang google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5: attribute_context.AttributeContext_Peer. go 1.26 · linux…
sha256:3a2b94238e4f9a7a001116ba7d7c7c2ba9c57e72b03929bee251683516ab2f7e
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
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 google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext_Peer in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260825221802-da73d73af1c5
- シンボル
-
- google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext_Peer
- 作成日
- 2026-09-03T04:33:25Z
コントラクト
- AttributeContext_Peer fields are initialized correctly
- FormatEndpoint formats ip and port as endpoint string
- GetLabel retrieves label value or returns false if missing
- nil AttributeContext_Peer getters return zero values safely
- Reset clears all fields of AttributeContext_Peer
- ProtoReflect returns non-nil valid protoreflect.Message
- AttributeContext embeds AttributeContext_Peer in Source and Destination
ファイル
- PROMPT.md
- csx.json
- go.mod
- go.sum
- peer.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 google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext_Peer in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260825221802-da73d73af1c5
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260825221802-da73d73af1c5
Demonstrate these symbols/APIs:
- google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext_Peer
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:3642933a5d957bb2ad4d424cabdf174423c1d798c3aa1bbc45c5893c2a5b19f8","contract":["AttributeContext_Peer fields are initialized correctly","FormatEndpoint formats ip and port as endpoint string","GetLabel retrieves label value or returns false if missing","nil AttributeContext_Peer getters return zero values safely","Reset clears all fields of AttributeContext_Peer","ProtoReflect returns non-nil valid protoreflect.Message","AttributeContext embeds AttributeContext_Peer in Source and Destination"],"goal":"verify google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext_Peer in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260825221802-da73d73af1c5","kind":"HOW","packages":["pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260825221802-da73d73af1c5"],"schemaVersion":1,"symbols":["google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext_Peer"]},"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/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260825221802-da73d73af1c5"],"schemaVersion":1,"subject":"pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260825221802-da73d73af1c5","symbols":["google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext_Peer"],"verifierAdapter":"golang@1"}
module sample
go 1.26.6
require google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5
require google.golang.org/protobuf v1.36.12 // indirect
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5 h1:1VUiZAXyC+zmiFYi+WLtBzr68Cj8wOofHjjrA/kkizc=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5/go.mod h1:DjtHYE8FKJLivXcBEjGwndXfIC23G0VpXiXKqG179uA=
google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc=
google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
package sample
import (
"fmt"
"google.golang.org/genproto/googleapis/rpc/context/attribute_context"
)
// NewPeer constructs an AttributeContext_Peer with the provided fields.
func NewPeer(ip string, port int64, principal string, regionCode string, labels map[string]string) *attribute_context.AttributeContext_Peer {
return &attribute_context.AttributeContext_Peer{
Ip: ip,
Port: port,
Principal: principal,
RegionCode: regionCode,
Labels: labels,
}
}
// FormatEndpoint returns "ip:port" or empty string if IP is not set or peer is nil.
func FormatEndpoint(peer *attribute_context.AttributeContext_Peer) string {
if peer == nil || peer.GetIp() == "" {
return ""
}
return fmt.Sprintf("%s:%d", peer.GetIp(), peer.GetPort())
}
// GetLabel returns the value of the label key, or ("", false) if not found or peer is nil.
func GetLabel(peer *attribute_context.AttributeContext_Peer, key string) (string, bool) {
if peer == nil {
return "", false
}
labels := peer.GetLabels()
if labels == nil {
return "", false
}
val, ok := labels[key]
return val, ok
}
{
"schemaVersion": 1,
"goal": "verify google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext_Peer in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260825221802-da73d73af1c5",
"kind": "HOW",
"packages": [
"pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260825221802-da73d73af1c5"
],
"symbols": [
"google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext_Peer"
]
}
package main
import (
"fmt"
"os"
"google.golang.org/genproto/googleapis/rpc/context/attribute_context"
"sample"
)
func main() {
labels := map[string]string{
"env": "prod",
"tier": "frontend",
}
peer := sample.NewPeer("192.0.2.1", 8080, "spiffe://example.com/sa/client", "US", labels)
// Assertion 1: AttributeContext_Peer fields are initialized correctly
if peer.GetIp() != "192.0.2.1" {
fmt.Fprintf(os.Stderr, "expected GetIp() to equal 192.0.2.1, got %q\n", peer.GetIp())
os.Exit(1)
}
if peer.GetPort() != 8080 {
fmt.Fprintf(os.Stderr, "expected GetPort() to equal 8080, got %d\n", peer.GetPort())
os.Exit(1)
}
if peer.GetPrincipal() != "spiffe://example.com/sa/client" {
fmt.Fprintf(os.Stderr, "expected GetPrincipal() to equal spiffe://example.com/sa/client, got %q\n", peer.GetPrincipal())
os.Exit(1)
}
if peer.GetRegionCode() != "US" {
fmt.Fprintf(os.Stderr, "expected GetRegionCode() to equal US, got %q\n", peer.GetRegionCode())
os.Exit(1)
}
if peer.GetLabels()["env"] != "prod" || peer.GetLabels()["tier"] != "frontend" {
fmt.Fprintf(os.Stderr, "labels mismatch in peer: %v\n", peer.GetLabels())
os.Exit(1)
}
// Assertion 2: FormatEndpoint formats ip and port as endpoint string
if endpoint := sample.FormatEndpoint(peer); endpoint != "192.0.2.1:8080" {
fmt.Fprintf(os.Stderr, "expected endpoint 192.0.2.1:8080, got %q\n", endpoint)
os.Exit(1)
}
// Assertion 3: GetLabel retrieves label value or returns false if missing
if val, ok := sample.GetLabel(peer, "env"); !ok || val != "prod" {
fmt.Fprintf(os.Stderr, "expected GetLabel('env') to be (prod, true), got (%q, %t)\n", val, ok)
os.Exit(1)
}
if _, ok := sample.GetLabel(peer, "nonexistent"); ok {
fmt.Fprintf(os.Stderr, "expected GetLabel('nonexistent') to return false\n")
os.Exit(1)
}
// Assertion 4: nil AttributeContext_Peer getters return zero values safely
var nilPeer *attribute_context.AttributeContext_Peer
if nilPeer.GetIp() != "" || nilPeer.GetPort() != 0 || nilPeer.GetPrincipal() != "" || nilPeer.GetRegionCode() != "" || nilPeer.GetLabels() != nil {
fmt.Fprintf(os.Stderr, "expected zero values from nil peer getters\n")
os.Exit(1)
}
if sample.FormatEndpoint(nilPeer) != "" {
fmt.Fprintf(os.Stderr, "expected FormatEndpoint(nil) to return empty string\n")
os.Exit(1)
}
if _, ok := sample.GetLabel(nilPeer, "env"); ok {
fmt.Fprintf(os.Stderr, "expected GetLabel(nil, 'env') to return false\n")
os.Exit(1)
}
// Assertion 5: Reset clears all fields of AttributeContext_Peer
resetPeer := sample.NewPeer("198.51.100.1", 443, "user", "CA", map[string]string{"k": "v"})
resetPeer.Reset()
if resetPeer.GetIp() != "" || resetPeer.GetPort() != 0 || resetPeer.GetPrincipal() != "" || resetPeer.GetRegionCode() != "" || resetPeer.GetLabels() != nil {
fmt.Fprintf(os.Stderr, "expected Reset() to clear all fields\n")
os.Exit(1)
}
// Assertion 6: ProtoReflect returns non-nil valid protoreflect.Message
msg := peer.ProtoReflect()
if msg == nil || !msg.IsValid() {
fmt.Fprintf(os.Stderr, "expected valid protoreflect.Message from ProtoReflect()\n")
os.Exit(1)
}
// Assertion 7: AttributeContext embeds AttributeContext_Peer in Source and Destination
attrCtx := &attribute_context.AttributeContext{
Source: peer,
Destination: sample.NewPeer("198.51.100.2", 9090, "service-b", "US", nil),
}
if attrCtx.GetSource().GetIp() != "192.0.2.1" {
fmt.Fprintf(os.Stderr, "expected GetSource().GetIp() to be 192.0.2.1, got %q\n", attrCtx.GetSource().GetIp())
os.Exit(1)
}
if attrCtx.GetDestination().GetPort() != 9090 {
fmt.Fprintf(os.Stderr, "expected GetDestination().GetPort() to be 9090, got %d\n", attrCtx.GetDestination().GetPort())
os.Exit(1)
}
fmt.Println("All google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext_Peer contract assertions passed.")
}
オリジンシーダー
匿名