CodeSampleX

샘플

google.golang.org/genproto/googleapis/api v0.0.0-20241007155032-5fefd90f89a9: annotations.HttpRule_Get

검증된 샘플 — golang google.golang.org/genproto/googleapis/api v0.0.0-20241007155032-5fefd90f89a9: annotations.HttpRule_Get. go 1.26 · linux alpine/x64 · docker에서…

sha256:6df40c035764bf48a89afbe584786c2fea19d0aa36ee9cd1dacdc49359cd1be4

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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/api/annotations.HttpRule_Get in pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20241007155032-5fefd90f89a9
패키지
심벌
  • google.golang.org/genproto/googleapis/api/annotations.HttpRule_Get
생성일
2026-08-27T12:04:28Z

컨트랙트

  1. annotations.HttpRule_Get encapsulates HTTP GET url template string within HttpRule Pattern oneof
  2. annotations.HttpRule_Get enables direct type assertion from HttpRule Pattern interface
  3. annotations.HttpRule_Get round-trips through protobuf wire format serialization and deserialization
  4. HttpRule.GetGet helper method extracts URL template from active HttpRule_Get and returns empty string when another pattern is active

파일

  • 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/api/annotations.HttpRule_Get in pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20241007155032-5fefd90f89a9
Kind: HOW

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

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:603f5fc22dbd083d18f7336c2702786ff7448b0e3fdadd80ac9b5e3bd130afbf","contract":["annotations.HttpRule_Get encapsulates HTTP GET url template string within HttpRule Pattern oneof","annotations.HttpRule_Get enables direct type assertion from HttpRule Pattern interface","annotations.HttpRule_Get round-trips through protobuf wire format serialization and deserialization","HttpRule.GetGet helper method extracts URL template from active HttpRule_Get and returns empty string when another pattern is active"],"goal":"verify google.golang.org/genproto/googleapis/api/annotations.HttpRule_Get in pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20241007155032-5fefd90f89a9","kind":"HOW","packages":["pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20241007155032-5fefd90f89a9"],"schemaVersion":1,"symbols":["google.golang.org/genproto/googleapis/api/annotations.HttpRule_Get"]},"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/api@v0.0.0-20241007155032-5fefd90f89a9"],"schemaVersion":1,"subject":"pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20241007155032-5fefd90f89a9","symbols":["google.golang.org/genproto/googleapis/api/annotations.HttpRule_Get"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.22

require (
	google.golang.org/genproto/googleapis/api v0.0.0-20241007155032-5fefd90f89a9
	google.golang.org/protobuf v1.35.1
)
go.sum
google.golang.org/genproto/googleapis/api v0.0.0-20241007155032-5fefd90f89a9 h1:T6rh4haD3GVYsgEfWExoCZA2o2FmbNyKpTuAxbEFPTg=
google.golang.org/genproto/googleapis/api v0.0.0-20241007155032-5fefd90f89a9/go.mod h1:wp2WsuBYj6j8wUdo3ToZsdxxixbvQNAHqVJrTgi5E5M=
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"

	"google.golang.org/genproto/googleapis/api/annotations"
	"google.golang.org/protobuf/proto"
)

func main() {
	// Create an HttpRule specifying an HTTP GET mapping using HttpRule_Get
	rule := &annotations.HttpRule{
		Selector: "google.example.library.v1.LibraryService.GetBook",
		Pattern: &annotations.HttpRule_Get{
			Get: "/v1/{name=publishers/*/books/*}",
		},
	}

	// Direct access via type assertion on Pattern interface
	if getPattern, ok := rule.GetPattern().(*annotations.HttpRule_Get); ok {
		fmt.Printf("HTTP GET pattern: %s\n", getPattern.Get)
	}

	// Serialization and deserialization round-trip
	data, err := proto.Marshal(rule)
	if err != nil {
		log.Fatalf("failed to marshal HttpRule: %v", err)
	}

	var decoded annotations.HttpRule
	if err := proto.Unmarshal(data, &decoded); err != nil {
		log.Fatalf("failed to unmarshal HttpRule: %v", err)
	}

	fmt.Printf("Decoded GET URL: %s\n", decoded.GetGet())
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify google.golang.org/genproto/googleapis/api/annotations.HttpRule_Get in pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20241007155032-5fefd90f89a9",
  "kind": "HOW",
  "packages": [
    "pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20241007155032-5fefd90f89a9"
  ],
  "symbols": [
    "google.golang.org/genproto/googleapis/api/annotations.HttpRule_Get"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"google.golang.org/genproto/googleapis/api/annotations"
	"google.golang.org/protobuf/proto"
)

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

func main() {
	// 1. annotations.HttpRule_Get encapsulates HTTP GET URL template string within HttpRule Pattern
	getPattern := &annotations.HttpRule_Get{
		Get: "/v1/shelves/{shelf_id}/books/{book_id}",
	}
	assert(getPattern.Get == "/v1/shelves/{shelf_id}/books/{book_id}", "HttpRule_Get.Get string field must match initialized value")

	rule := &annotations.HttpRule{
		Selector: "google.example.library.v1.LibraryService.GetBook",
		Pattern:  getPattern,
	}

	// 2. annotations.HttpRule_Get satisfies isHttpRule_Pattern interface and allows direct type assertion
	patternFromGetter := rule.GetPattern()
	assert(patternFromGetter != nil, "rule.GetPattern() must not be nil")

	assertedGet, ok := patternFromGetter.(*annotations.HttpRule_Get)
	assert(ok, "rule.GetPattern() must type-assert successfully to *annotations.HttpRule_Get")
	assert(assertedGet.Get == "/v1/shelves/{shelf_id}/books/{book_id}", "asserted HttpRule_Get.Get must match original template")

	// 3. annotations.HttpRule_Get round-trips through protobuf wire format serialization and deserialization
	data, err := proto.Marshal(rule)
	assert(err == nil, "proto.Marshal(rule) must succeed")
	assert(len(data) > 0, "marshaled payload must not be empty")

	var decoded annotations.HttpRule
	err = proto.Unmarshal(data, &decoded)
	assert(err == nil, "proto.Unmarshal(data) must succeed")
	assert(decoded.GetSelector() == rule.GetSelector(), "decoded selector must match original")

	decodedPattern, ok := decoded.GetPattern().(*annotations.HttpRule_Get)
	assert(ok, "decoded pattern must type-assert to *annotations.HttpRule_Get")
	assert(decodedPattern.Get == "/v1/shelves/{shelf_id}/books/{book_id}", "decoded HttpRule_Get.Get must match original template")

	// 4. HttpRule.GetGet helper method extracts URL template from active HttpRule_Get and returns empty string when another pattern is active
	assert(decoded.GetGet() == "/v1/shelves/{shelf_id}/books/{book_id}", "decoded.GetGet() helper must return active GET path")

	postRule := &annotations.HttpRule{
		Selector: "google.example.library.v1.LibraryService.CreateBook",
		Pattern: &annotations.HttpRule_Post{
			Post: "/v1/shelves/{shelf_id}/books",
		},
	}
	assert(postRule.GetGet() == "", "postRule.GetGet() must return empty string when pattern is not HttpRule_Get")
	_, isGet := postRule.GetPattern().(*annotations.HttpRule_Get)
	assert(!isGet, "postRule pattern must not type-assert to *annotations.HttpRule_Get")

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

오리진 시더

익명