CodeSampleX

示例

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

已验证示例 — golang google.golang.org/genproto/googleapis/api v0.0.0-20241007155032-5fefd90f89a9: annotations.HttpRule_Put. contract 在 go 1.26 · linux alpine/x64…

sha256:e66c5a37e5d3915c3dd376e3ff4141abe5cad9483739ca30e43f65e1c8f65e96

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 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_Put in pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20241007155032-5fefd90f89a9
包
符号
  • google.golang.org/genproto/googleapis/api/annotations.HttpRule_Put
创建时间
2026-08-27T12:13:07Z

契约

  1. annotations.HttpRule_Put encapsulates the PUT URL template for HttpRule
  2. annotations.HttpRule configured with HttpRule_Put returns PUT URL via GetPut and GetPattern
  3. annotations.HttpRule.GetPattern resolves to *annotations.HttpRule_Put via type assertion
  4. annotations.HttpRule with HttpRule_Put serializes and deserializes accurately with protobuf wire format

文件

  • 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_Put 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_Put
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: esm
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:5339d2c969575d18e9cf81c8342a78dd90737b6c90e31bd3dce9dd9c773dea96","contract":["annotations.HttpRule_Put encapsulates the PUT URL template for HttpRule","annotations.HttpRule configured with HttpRule_Put returns PUT URL via GetPut and GetPattern","annotations.HttpRule.GetPattern resolves to *annotations.HttpRule_Put via type assertion","annotations.HttpRule with HttpRule_Put serializes and deserializes accurately with protobuf wire format"],"goal":"verify google.golang.org/genproto/googleapis/api/annotations.HttpRule_Put 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_Put"]},"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_Put"],"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() {
	putPattern := &annotations.HttpRule_Put{
		Put: "/v1/{name=publishers/*/books/*}",
	}

	rule := &annotations.HttpRule{
		Selector: "google.example.library.v1.LibraryService.UpdateBook",
		Pattern:  putPattern,
		Body:     "book",
	}

	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("Selector: %s\n", decoded.GetSelector())
	fmt.Printf("HTTP PUT Pattern: %s\n", decoded.GetPut())
	fmt.Printf("Body: %s\n", decoded.GetBody())
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify google.golang.org/genproto/googleapis/api/annotations.HttpRule_Put 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_Put"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "esm",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
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. HttpRule_Put encapsulates the PUT URL template for HttpRule
	putPattern := &annotations.HttpRule_Put{
		Put: "/v1/{name=publishers/*/books/*}",
	}
	assert(putPattern.Put == "/v1/{name=publishers/*/books/*}", "Put field must match initialized value")

	// 2. HttpRule configured with HttpRule_Put returns PUT URL via GetPut and GetPattern
	rule := &annotations.HttpRule{
		Selector: "google.example.library.v1.LibraryService.UpdateBook",
		Pattern:  putPattern,
		Body:     "book",
	}
	assert(rule.GetSelector() == "google.example.library.v1.LibraryService.UpdateBook", "selector must match")
	assert(rule.GetPut() == "/v1/{name=publishers/*/books/*}", "GetPut must return configured PUT path")
	assert(rule.GetGet() == "", "GetGet must return empty string for PUT rule")
	assert(rule.GetPost() == "", "GetPost must return empty string for PUT rule")
	assert(rule.GetBody() == "book", "body mapping must match")

	// 3. Pattern interface resolves to *annotations.HttpRule_Put via type assertion
	switch p := rule.GetPattern().(type) {
	case *annotations.HttpRule_Put:
		assert(p.Put == "/v1/{name=publishers/*/books/*}", "type assertion to *HttpRule_Put must match path")
	default:
		assert(false, "pattern must be of type *annotations.HttpRule_Put")
	}

	// 4. HttpRule with HttpRule_Put marshals and unmarshals accurately with protobuf wire format
	data, err := proto.Marshal(rule)
	assert(err == nil, "proto.Marshal must succeed")
	assert(len(data) > 0, "marshaled bytes must not be empty")

	var decoded annotations.HttpRule
	err = proto.Unmarshal(data, &decoded)
	assert(err == nil, "proto.Unmarshal must succeed")
	assert(decoded.GetSelector() == rule.GetSelector(), "decoded selector must match")
	assert(decoded.GetPut() == "/v1/{name=publishers/*/books/*}", "decoded GetPut must match")
	assert(decoded.GetBody() == "book", "decoded body must match")

	// Verify decoded pattern type
	if putDecoded, ok := decoded.GetPattern().(*annotations.HttpRule_Put); ok {
		assert(putDecoded.Put == "/v1/{name=publishers/*/books/*}", "decoded pattern Put field must match")
	} else {
		assert(false, "decoded pattern must be *annotations.HttpRule_Put")
	}

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

原始种子者

匿名