CodeSampleX

샘플

google.golang.org/genproto/googleapis/rpc v0.0.0-20260427160629-7cedc36a6bc4: attribute_context.AttributeContext

검증된 샘플 — golang google.golang.org/genproto/googleapis/rpc v0.0.0-20260427160629-7cedc36a6bc4: attribute_context.AttributeContext. go 1.26 · linux debian/x64…

sha256:80c3847c259f5cdf075a620ec042a4788fe276edcbdfa13fd83742e316b52a71

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 go linux 24 · ubuntu · glibc 2.39 x64 go go 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 google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260427160629-7cedc36a6bc4
패키지
심벌
  • google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext
환경
go
생성일
2026-09-01T10:34:34Z

컨트랙트

  1. AttributeContext fields Request, Response, Origin, Source, Destination, and Resource store structured RPC metadata accessible via getters.
  2. AttributeContext and its nested fields return safe nil or empty values when called on nil receivers.
  3. AttributeContext serializes to and deserializes from protocol buffer binary format preserving nested Request, Response, and Peer details.
  4. AttributeContext.Reset clears all fields and resets the message back to zero state.
  5. AttributeContext_Request stores Method, Path, Host, Headers, and Auth metadata accurately.

파일

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract_test.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/context/attribute_context.AttributeContext in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260427160629-7cedc36a6bc4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260427160629-7cedc36a6bc4
Demonstrate these symbols/APIs:
  - google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext

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:4ddaed5377c7895fd95329d32c7c309f3cfcf97fb7b45ed294097a4f00f820fa","contract":["AttributeContext fields Request, Response, Origin, Source, Destination, and Resource store structured RPC metadata accessible via getters.","AttributeContext and its nested fields return safe nil or empty values when called on nil receivers.","AttributeContext serializes to and deserializes from protocol buffer binary format preserving nested Request, Response, and Peer details.","AttributeContext.Reset clears all fields and resets the message back to zero state.","AttributeContext_Request stores Method, Path, Host, Headers, and Auth metadata accurately."],"goal":"verify google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260427160629-7cedc36a6bc4","kind":"HOW","packages":["pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260427160629-7cedc36a6bc4"],"schemaVersion":1,"symbols":["google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext"]},"contractCommand":["go","test","./..."],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","executionContext":"go","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","runtime":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260427160629-7cedc36a6bc4"],"schemaVersion":1,"subject":"pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260427160629-7cedc36a6bc4","symbols":["google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext"],"verifierAdapter":"golang@1"}
go.mod
module example.com/attributecontext

go 1.25.0

require (
	google.golang.org/genproto/googleapis/rpc v0.0.0-20260427160629-7cedc36a6bc4
	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-20260427160629-7cedc36a6bc4 h1:tEkOQcXgF6dH1G+MVKZrfpYvozGrzb91k6ha7jireSM=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260427160629-7cedc36a6bc4/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
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() {
	attr := &attribute_context.AttributeContext{
		Origin: &attribute_context.AttributeContext_Peer{
			Ip:   "192.0.2.1",
			Port: 8080,
		},
		Request: &attribute_context.AttributeContext_Request{
			Id:     "req-12345",
			Method: "POST",
			Path:   "/v1/resources",
			Host:   "example.com",
			Scheme: "https",
			Headers: map[string]string{
				"content-type": "application/json",
			},
			Auth: &attribute_context.AttributeContext_Auth{
				Principal: "user-service@example.com",
			},
		},
		Response: &attribute_context.AttributeContext_Response{
			Code: 200,
			Size: 512,
		},
		Resource: &attribute_context.AttributeContext_Resource{
			Service: "resource-service",
			Name:    "items",
			Type:    "type.googleapis.com/example.Item",
		},
	}

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

	var decoded attribute_context.AttributeContext
	if err := proto.Unmarshal(data, &decoded); err != nil {
		panic(err)
	}

	fmt.Printf("Request Method: %s\n", decoded.GetRequest().GetMethod())
	fmt.Printf("Request Path: %s\n", decoded.GetRequest().GetPath())
	fmt.Printf("Origin IP: %s\n", decoded.GetOrigin().GetIp())
	fmt.Printf("Response Code: %d\n", decoded.GetResponse().GetCode())
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260427160629-7cedc36a6bc4",
  "kind": "HOW",
  "packages": [
    "pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260427160629-7cedc36a6bc4"
  ],
  "symbols": [
    "google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext"
  ]
}
test/contract_test.go
package test

import (
	"testing"

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

func TestAttributeContextFieldsAndGetters(t *testing.T) {
	req := &attribute_context.AttributeContext_Request{
		Id:     "req-101",
		Method: "GET",
		Path:   "/api/items",
		Host:   "example.com",
		Scheme: "https",
	}
	resp := &attribute_context.AttributeContext_Response{
		Code: 200,
		Size: 1024,
	}
	origin := &attribute_context.AttributeContext_Peer{
		Ip:   "192.0.2.1",
		Port: 8080,
	}
	source := &attribute_context.AttributeContext_Peer{
		Ip:   "10.0.0.1",
		Port: 443,
	}
	dest := &attribute_context.AttributeContext_Peer{
		Ip:   "10.0.0.2",
		Port: 8443,
	}
	resource := &attribute_context.AttributeContext_Resource{
		Service: "catalog-service",
		Name:    "catalog-item-1",
		Type:    "type.googleapis.com/example.CatalogItem",
	}

	ctx := &attribute_context.AttributeContext{
		Origin:      origin,
		Source:      source,
		Destination: dest,
		Request:     req,
		Response:    resp,
		Resource:    resource,
	}

	if got := ctx.GetOrigin().GetIp(); got != "192.0.2.1" {
		t.Errorf("GetOrigin().GetIp() = %q, want %q", got, "192.0.2.1")
	}
	if got := ctx.GetSource().GetIp(); got != "10.0.0.1" {
		t.Errorf("GetSource().GetIp() = %q, want %q", got, "10.0.0.1")
	}
	if got := ctx.GetDestination().GetPort(); got != 8443 {
		t.Errorf("GetDestination().GetPort() = %d, want 8443", got)
	}
	if got := ctx.GetRequest().GetMethod(); got != "GET" {
		t.Errorf("GetRequest().GetMethod() = %q, want %q", got, "GET")
	}
	if got := ctx.GetResponse().GetCode(); got != 200 {
		t.Errorf("GetResponse().GetCode() = %d, want 200", got)
	}
	if got := ctx.GetResource().GetService(); got != "catalog-service" {
		t.Errorf("GetResource().GetService() = %q, want %q", got, "catalog-service")
	}
}

func TestAttributeContextNilSafeGetters(t *testing.T) {
	var nilCtx *attribute_context.AttributeContext

	if nilCtx.GetOrigin() != nil {
		t.Errorf("nilCtx.GetOrigin() expected nil, got %v", nilCtx.GetOrigin())
	}
	if nilCtx.GetSource() != nil {
		t.Errorf("nilCtx.GetSource() expected nil, got %v", nilCtx.GetSource())
	}
	if nilCtx.GetDestination() != nil {
		t.Errorf("nilCtx.GetDestination() expected nil, got %v", nilCtx.GetDestination())
	}
	if nilCtx.GetRequest() != nil {
		t.Errorf("nilCtx.GetRequest() expected nil, got %v", nilCtx.GetRequest())
	}
	if nilCtx.GetResponse() != nil {
		t.Errorf("nilCtx.GetResponse() expected nil, got %v", nilCtx.GetResponse())
	}
	if nilCtx.GetResource() != nil {
		t.Errorf("nilCtx.GetResource() expected nil, got %v", nilCtx.GetResource())
	}
	if nilCtx.GetApi() != nil {
		t.Errorf("nilCtx.GetApi() expected nil, got %v", nilCtx.GetApi())
	}

	var nilReq *attribute_context.AttributeContext_Request
	if got := nilReq.GetId(); got != "" {
		t.Errorf("nilReq.GetId() = %q, want empty string", got)
	}
	if got := nilReq.GetMethod(); got != "" {
		t.Errorf("nilReq.GetMethod() = %q, want empty string", got)
	}
	if nilReq.GetHeaders() != nil {
		t.Errorf("nilReq.GetHeaders() expected nil, got %v", nilReq.GetHeaders())
	}
	if nilReq.GetAuth() != nil {
		t.Errorf("nilReq.GetAuth() expected nil, got %v", nilReq.GetAuth())
	}
}

func TestAttributeContextProtoSerialization(t *testing.T) {
	original := &attribute_context.AttributeContext{
		Origin: &attribute_context.AttributeContext_Peer{
			Ip:   "198.51.100.1",
			Port: 9000,
		},
		Request: &attribute_context.AttributeContext_Request{
			Id:     "req-roundtrip",
			Method: "PUT",
			Path:   "/v1/records/42",
			Host:   "example.com",
			Scheme: "https",
		},
		Response: &attribute_context.AttributeContext_Response{
			Code: 204,
		},
	}

	data, err := proto.Marshal(original)
	if err != nil {
		t.Fatalf("proto.Marshal failed: %v", err)
	}

	var decoded attribute_context.AttributeContext
	if err := proto.Unmarshal(data, &decoded); err != nil {
		t.Fatalf("proto.Unmarshal failed: %v", err)
	}

	if decoded.GetRequest().GetId() != original.GetRequest().GetId() {
		t.Errorf("decoded Request.Id = %q, want %q", decoded.GetRequest().GetId(), original.GetRequest().GetId())
	}
	if decoded.GetRequest().GetMethod() != original.GetRequest().GetMethod() {
		t.Errorf("decoded Request.Method = %q, want %q", decoded.GetRequest().GetMethod(), original.GetRequest().GetMethod())
	}
	if decoded.GetOrigin().GetIp() != original.GetOrigin().GetIp() {
		t.Errorf("decoded Origin.Ip = %q, want %q", decoded.GetOrigin().GetIp(), original.GetOrigin().GetIp())
	}
	if decoded.GetResponse().GetCode() != original.GetResponse().GetCode() {
		t.Errorf("decoded Response.Code = %d, want %d", decoded.GetResponse().GetCode(), original.GetResponse().GetCode())
	}
}

func TestAttributeContextReset(t *testing.T) {
	ctx := &attribute_context.AttributeContext{
		Request: &attribute_context.AttributeContext_Request{
			Id:     "req-to-reset",
			Method: "DELETE",
		},
		Response: &attribute_context.AttributeContext_Response{
			Code: 200,
		},
	}

	ctx.Reset()

	if ctx.GetRequest() != nil {
		t.Errorf("Reset() did not clear Request: got %v", ctx.GetRequest())
	}
	if ctx.GetResponse() != nil {
		t.Errorf("Reset() did not clear Response: got %v", ctx.GetResponse())
	}
}

func TestAttributeContextRequestMetadata(t *testing.T) {
	req := &attribute_context.AttributeContext_Request{
		Id:     "req-meta",
		Method: "POST",
		Path:   "/api/v2/orders",
		Host:   "order.example.com",
		Headers: map[string]string{
			"content-type": "application/json",
			"x-api-key":    "test-key",
		},
		Auth: &attribute_context.AttributeContext_Auth{
			Principal: "service-account@example.com",
			Audiences: []string{"order.example.com"},
		},
	}

	if got := req.GetMethod(); got != "POST" {
		t.Errorf("GetMethod() = %q, want %q", got, "POST")
	}
	if got := req.GetPath(); got != "/api/v2/orders" {
		t.Errorf("GetPath() = %q, want %q", got, "/api/v2/orders")
	}
	if got := req.GetHost(); got != "order.example.com" {
		t.Errorf("GetHost() = %q, want %q", got, "order.example.com")
	}
	if got := req.GetHeaders()["content-type"]; got != "application/json" {
		t.Errorf("Headers[content-type] = %q, want application/json", got)
	}
	if got := req.GetAuth().GetPrincipal(); got != "service-account@example.com" {
		t.Errorf("GetAuth().GetPrincipal() = %q, want service-account@example.com", got)
	}
}

오리진 시더

익명