CodeSampleX

サンプル

google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9: errdetails.RetryInfo

検証済みサンプル — golang google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9: errdetails.RetryInfo. go 1.26 · linux alpine/x64 · docker で…

sha256:d43d71899d406ff6170b741f3ccd4cb3ff0b900221e87667c30a1e0d34b0d25b

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux 24 · ubuntu · glibc 2.39 x64 go

検証実行環境

環境 コントラクト ステージ 実行日
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-27

ケース

HOW
ゴール
verify google.golang.org/genproto/googleapis/rpc/errdetails.RetryInfo in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9
パッケージ
シンボル
  • google.golang.org/genproto/googleapis/rpc/errdetails.RetryInfo
作成日
2026-08-27T11:57:22Z

コントラクト

  1. RetryInfo initializes with durationpb RetryDelay and retrieves duration accurately
  2. RetryInfo packs into anypb.Any and unpacks back successfully
  3. RetryInfo integrates into status.Status details and roundtrips through proto serialization
  4. RetryInfo handles nil RetryDelay safely returning nil
  5. RetryInfo message matches anypb.MessageIs type check

ファイル

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.go

ソースアーティファクトをダウンロード (tar.gz)

ソース

PROMPT.md
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/errdetails.RetryInfo in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9
Demonstrate these symbols/APIs:
  - google.golang.org/genproto/googleapis/rpc/errdetails.RetryInfo

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.
csx.json
{"case":{"caseId":"case:sha256:8e2350702b52e0b6768d46e683a56bd82424abb19c113991a3a0cf6af0b4f4ab","contract":["RetryInfo initializes with durationpb RetryDelay and retrieves duration accurately","RetryInfo packs into anypb.Any and unpacks back successfully","RetryInfo integrates into status.Status details and roundtrips through proto serialization","RetryInfo handles nil RetryDelay safely returning nil","RetryInfo message matches anypb.MessageIs type check"],"goal":"verify google.golang.org/genproto/googleapis/rpc/errdetails.RetryInfo in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9","kind":"HOW","packages":["pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9"],"schemaVersion":1,"symbols":["google.golang.org/genproto/googleapis/rpc/errdetails.RetryInfo"]},"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-20241007155032-5fefd90f89a9"],"schemaVersion":1,"subject":"pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9","symbols":["google.golang.org/genproto/googleapis/rpc/errdetails.RetryInfo"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.22

require (
	google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9
	google.golang.org/protobuf v1.35.1
)
go.sum
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 h1:QCqS/PdaHTSWGvupk2F/ehwHtGc0/GYkT+3GAcR1CCc=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
main.go
package main

import (
	"fmt"
	"log"
	"time"

	"google.golang.org/genproto/googleapis/rpc/code"
	"google.golang.org/genproto/googleapis/rpc/errdetails"
	"google.golang.org/genproto/googleapis/rpc/status"
	"google.golang.org/protobuf/proto"
	"google.golang.org/protobuf/types/known/anypb"
	"google.golang.org/protobuf/types/known/durationpb"
)

func main() {
	// 1. Create a RetryInfo detail indicating a retry backoff duration
	retryInfo := &errdetails.RetryInfo{
		RetryDelay: durationpb.New(15 * time.Second),
	}

	// 2. Pack RetryInfo into Any protobuf message
	anyRetryInfo, err := anypb.New(retryInfo)
	if err != nil {
		log.Fatalf("failed to pack retry info: %v", err)
	}

	// 3. Attach RetryInfo Any message into standard RPC status
	rpcStatus := &status.Status{
		Code:    int32(code.Code_UNAVAILABLE),
		Message: "service temporarily unavailable, please retry later",
		Details: []*anypb.Any{anyRetryInfo},
	}

	// 4. Serialize Status to binary protobuf
	data, err := proto.Marshal(rpcStatus)
	if err != nil {
		log.Fatalf("failed to marshal status: %v", err)
	}

	// 5. Unmarshal and unpack RetryInfo
	var decoded status.Status
	if err := proto.Unmarshal(data, &decoded); err != nil {
		log.Fatalf("failed to unmarshal status: %v", err)
	}

	for _, detail := range decoded.GetDetails() {
		if detail.MessageIs(&errdetails.RetryInfo{}) {
			unpacked := &errdetails.RetryInfo{}
			if err := detail.UnmarshalTo(unpacked); err != nil {
				log.Fatalf("failed to unpack detail: %v", err)
			}
			fmt.Printf("Retry delay: %v\n", unpacked.GetRetryDelay().AsDuration())
		}
	}
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify google.golang.org/genproto/googleapis/rpc/errdetails.RetryInfo in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9",
  "kind": "HOW",
  "packages": [
    "pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9"
  ],
  "symbols": [
    "google.golang.org/genproto/googleapis/rpc/errdetails.RetryInfo"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"
	"time"

	"google.golang.org/genproto/googleapis/rpc/code"
	"google.golang.org/genproto/googleapis/rpc/errdetails"
	"google.golang.org/genproto/googleapis/rpc/status"
	"google.golang.org/protobuf/proto"
	"google.golang.org/protobuf/types/known/anypb"
	"google.golang.org/protobuf/types/known/durationpb"
)

func assert(condition bool, message string) {
	if !condition {
		fmt.Fprintf(os.Stderr, "Assertion failed: %s\n", message)
		os.Exit(1)
	}
}

func main() {
	// 1. RetryInfo initializes with durationpb RetryDelay and retrieves duration accurately
	expectedDuration := 10 * time.Second
	retryInfo := &errdetails.RetryInfo{
		RetryDelay: durationpb.New(expectedDuration),
	}
	assert(retryInfo.GetRetryDelay() != nil, "RetryDelay should not be nil")
	assert(retryInfo.GetRetryDelay().GetSeconds() == 10, "RetryDelay seconds should be 10")
	assert(retryInfo.GetRetryDelay().GetNanos() == 0, "RetryDelay nanos should be 0")
	assert(retryInfo.GetRetryDelay().AsDuration() == expectedDuration, "RetryDelay AsDuration should match expectedDuration")

	// 2. RetryInfo packs into anypb.Any and unpacks back successfully
	anyMsg, err := anypb.New(retryInfo)
	assert(err == nil, "anypb.New(retryInfo) should succeed")
	assert(anyMsg != nil, "anyMsg should not be nil")

	unpacked := &errdetails.RetryInfo{}
	err = anypb.UnmarshalTo(anyMsg, unpacked, proto.UnmarshalOptions{})
	assert(err == nil, "UnmarshalTo should succeed")
	assert(unpacked.GetRetryDelay().AsDuration() == expectedDuration, "unpacked retry duration should match")

	// 3. RetryInfo integrates into status.Status details and roundtrips through proto serialization
	rpcStatus := &status.Status{
		Code:    int32(code.Code_UNAVAILABLE),
		Message: "service overloaded, please back off",
		Details: []*anypb.Any{anyMsg},
	}
	data, err := proto.Marshal(rpcStatus)
	assert(err == nil, "proto.Marshal should succeed")
	assert(len(data) > 0, "marshaled bytes should not be empty")

	var decodedStatus status.Status
	err = proto.Unmarshal(data, &decodedStatus)
	assert(err == nil, "proto.Unmarshal should succeed")
	assert(decodedStatus.GetCode() == int32(code.Code_UNAVAILABLE), "status code should match UNAVAILABLE")
	assert(len(decodedStatus.GetDetails()) == 1, "details count should be 1")

	// 4. RetryInfo handles nil RetryDelay safely returning nil
	nilRetryInfo := &errdetails.RetryInfo{}
	assert(nilRetryInfo.GetRetryDelay() == nil, "GetRetryDelay on empty RetryInfo should return nil")
	var typedNil *errdetails.RetryInfo
	assert(typedNil.GetRetryDelay() == nil, "GetRetryDelay on typed nil should return nil")

	// 5. RetryInfo message matches anypb.MessageIs type check
	assert(anyMsg.MessageIs(&errdetails.RetryInfo{}), "MessageIs should return true for RetryInfo")
	assert(!anyMsg.MessageIs(&errdetails.BadRequest{}), "MessageIs should return false for BadRequest")

	fmt.Println("All contract assertions passed successfully.")
}

オリジンシーダー

匿名