CodeSampleX

Beispiel

google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5: attribute_context.AttributeContext_Api

Verifiziertes Beispiel für golang google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5: attribute_context.AttributeContext_Api. Der…

sha256:420bbe1137cfcdea01d05ab8660d42530e1c22e9a8b37a923ba172433669dc2e

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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-07

Fall

HOW
Ziel
verify google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext_Api in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260825221802-da73d73af1c5
Pakete
Symbole
  • google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext_Api
Umgebung
go 1.26.6
Erstellt
2026-09-07T06:25:19Z

Contract

  1. AttributeContext_Api getters return empty strings for a nil receiver and return configured field values when set
  2. AttributeContext_Api serializes and deserializes accurately using proto.Marshal and proto.Unmarshal preserving all attributes
  3. AttributeContext_Api.Reset resets all fields to empty string zero values
  4. AttributeContext.GetApi returns nil for uninitialized context and returns the configured AttributeContext_Api instance when set

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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/context/attribute_context.AttributeContext_Api 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_Api

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:36427265c5e5e508d4374aad5040259fb814ec3fc3170e61a6fd8f35d478699f","contract":["AttributeContext_Api getters return empty strings for a nil receiver and return configured field values when set","AttributeContext_Api serializes and deserializes accurately using proto.Marshal and proto.Unmarshal preserving all attributes","AttributeContext_Api.Reset resets all fields to empty string zero values","AttributeContext.GetApi returns nil for uninitialized context and returns the configured AttributeContext_Api instance when set"],"goal":"verify google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext_Api 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_Api"]},"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/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_Api"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require (
	google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5
	google.golang.org/protobuf v1.36.12
)
go.sum
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=
main.go
package main

import (
	"fmt"

	"google.golang.org/genproto/googleapis/rpc/context/attribute_context"
	"google.golang.org/protobuf/proto"
)

func main() {
	api := &attribute_context.AttributeContext_Api{
		Service:   "example.com",
		Operation: "ExampleService.Echo",
		Protocol:  "grpc",
		Version:   "v1",
	}

	fmt.Printf("Service: %s\n", api.GetService())
	fmt.Printf("Operation: %s\n", api.GetOperation())
	fmt.Printf("Protocol: %s\n", api.GetProtocol())
	fmt.Printf("Version: %s\n", api.GetVersion())

	attrCtx := &attribute_context.AttributeContext{
		Api: api,
	}
	fmt.Printf("Context Api Service: %s\n", attrCtx.GetApi().GetService())

	data, err := proto.Marshal(api)
	if err != nil {
		panic(err)
	}

	var decoded attribute_context.AttributeContext_Api
	if err := proto.Unmarshal(data, &decoded); err != nil {
		panic(err)
	}
	fmt.Printf("Decoded service: %s\n", decoded.GetService())

	api.Reset()
	fmt.Printf("After reset service: %q\n", api.GetService())
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext_Api 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_Api"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"google.golang.org/genproto/googleapis/rpc/context/attribute_context"
	"google.golang.org/protobuf/proto"
)

func main() {
	if err := runContract(); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: %v\n", err)
		os.Exit(1)
	}
	fmt.Println("PASS: all contract assertions satisfied")
}

func runContract() error {
	// 1. AttributeContext_Api getters return empty strings for a nil receiver and return configured field values when set
	var nilApi *attribute_context.AttributeContext_Api
	if got := nilApi.GetService(); got != "" {
		return fmt.Errorf("nilApi.GetService() = %q, want empty", got)
	}
	if got := nilApi.GetOperation(); got != "" {
		return fmt.Errorf("nilApi.GetOperation() = %q, want empty", got)
	}
	if got := nilApi.GetProtocol(); got != "" {
		return fmt.Errorf("nilApi.GetProtocol() = %q, want empty", got)
	}
	if got := nilApi.GetVersion(); got != "" {
		return fmt.Errorf("nilApi.GetVersion() = %q, want empty", got)
	}

	api := &attribute_context.AttributeContext_Api{
		Service:   "example.com",
		Operation: "ExampleService.Echo",
		Protocol:  "grpc",
		Version:   "v1",
	}
	if api.GetService() != "example.com" {
		return fmt.Errorf("api.GetService() = %q, want %q", api.GetService(), "example.com")
	}
	if api.GetOperation() != "ExampleService.Echo" {
		return fmt.Errorf("api.GetOperation() = %q, want %q", api.GetOperation(), "ExampleService.Echo")
	}
	if api.GetProtocol() != "grpc" {
		return fmt.Errorf("api.GetProtocol() = %q, want %q", api.GetProtocol(), "grpc")
	}
	if api.GetVersion() != "v1" {
		return fmt.Errorf("api.GetVersion() = %q, want %q", api.GetVersion(), "v1")
	}

	// 2. AttributeContext_Api serializes and deserializes accurately using proto.Marshal and proto.Unmarshal preserving all attributes
	data, err := proto.Marshal(api)
	if err != nil {
		return fmt.Errorf("proto.Marshal failed: %w", err)
	}
	var decoded attribute_context.AttributeContext_Api
	if err := proto.Unmarshal(data, &decoded); err != nil {
		return fmt.Errorf("proto.Unmarshal failed: %w", err)
	}
	if decoded.GetService() != "example.com" || decoded.GetOperation() != "ExampleService.Echo" ||
		decoded.GetProtocol() != "grpc" || decoded.GetVersion() != "v1" {
		return fmt.Errorf("deserialized api mismatch: %+v", decoded)
	}

	// 3. AttributeContext_Api.Reset resets all fields to empty string zero values
	cloneApi := &attribute_context.AttributeContext_Api{
		Service:   "service.example.com",
		Operation: "Op",
		Protocol:  "http",
		Version:   "v2",
	}
	cloneApi.Reset()
	if cloneApi.GetService() != "" || cloneApi.GetOperation() != "" ||
		cloneApi.GetProtocol() != "" || cloneApi.GetVersion() != "" {
		return fmt.Errorf("after Reset(), api not cleared: %+v", cloneApi)
	}

	// 4. AttributeContext.GetApi returns nil for uninitialized context and returns the configured AttributeContext_Api instance when set
	var nilCtx *attribute_context.AttributeContext
	if got := nilCtx.GetApi(); got != nil {
		return fmt.Errorf("nilCtx.GetApi() = %v, want nil", got)
	}
	emptyCtx := &attribute_context.AttributeContext{}
	if got := emptyCtx.GetApi(); got != nil {
		return fmt.Errorf("emptyCtx.GetApi() = %v, want nil", got)
	}
	ctxWithApi := &attribute_context.AttributeContext{
		Api: api,
	}
	if got := ctxWithApi.GetApi(); got != api {
		return fmt.Errorf("ctxWithApi.GetApi() = %v, want %v", got, api)
	}

	return nil
}

Ursprungs-Seeder

anonym