CodeSampleX

サンプル

github.com/imdario/mergo v0.3.12: Merge

検証済みサンプル — golang github.com/imdario/mergo v0.3.12: Merge. go 1.26 · linux debian/x64 · docker で contract を実行し、成功しました: mergo.Merge merges non-zero fields…

sha256:c6dcacb2fbc2a23f26edd99bb26733535898be7e07c6b440c8f6bb2a10d07029

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

実行証拠

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

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

ケース

HOW
ゴール
verify github.com/imdario/mergo.Merge in pkg:golang/github.com/imdario/mergo@v0.3.12
パッケージ
シンボル
  • github.com/imdario/mergo.Merge
作成日
2026-09-04T14:54:01Z

コントラクト

  1. mergo.Merge merges non-zero fields from a source struct into zero-value fields of a destination struct pointer without overwriting existing non-zero fields
  2. mergo.Merge populates missing keys in a destination map from a source map while preserving existing destination keys
  3. mergo.Merge returns an error when destination is not a pointer

ファイル

  • 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 github.com/imdario/mergo.Merge in pkg:golang/github.com/imdario/mergo@v0.3.12
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/imdario/mergo@v0.3.12
Demonstrate these symbols/APIs:
  - github.com/imdario/mergo.Merge

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:46b26e05401c05ee19705e9d72671a9306b994a0da80b091df47a5dc71a9cd43","contract":["mergo.Merge merges non-zero fields from a source struct into zero-value fields of a destination struct pointer without overwriting existing non-zero fields","mergo.Merge populates missing keys in a destination map from a source map while preserving existing destination keys","mergo.Merge returns an error when destination is not a pointer"],"goal":"verify github.com/imdario/mergo.Merge in pkg:golang/github.com/imdario/mergo@v0.3.12","kind":"HOW","packages":["pkg:golang/github.com/imdario/mergo@v0.3.12"],"schemaVersion":1,"symbols":["github.com/imdario/mergo.Merge"]},"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/github.com/imdario/mergo@v0.3.12"],"schemaVersion":1,"subject":"pkg:golang/github.com/imdario/mergo@v0.3.12","symbols":["github.com/imdario/mergo.Merge"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require github.com/imdario/mergo v0.3.12
go.sum
github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
main.go
package main

import (
	"fmt"

	"github.com/imdario/mergo"
)

type Config struct {
	Host string
	Port int
	TLS  bool
}

func main() {
	defaultCfg := Config{
		Host: "localhost",
		Port: 8080,
		TLS:  true,
	}

	userCfg := Config{
		Port: 9000,
	}

	if err := mergo.Merge(&userCfg, defaultCfg); err != nil {
		panic(err)
	}

	fmt.Printf("Merged Config: Host=%s, Port=%d, TLS=%t\n", userCfg.Host, userCfg.Port, userCfg.TLS)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/imdario/mergo.Merge in pkg:golang/github.com/imdario/mergo@v0.3.12",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/imdario/mergo@v0.3.12"
  ],
  "symbols": [
    "github.com/imdario/mergo.Merge"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"github.com/imdario/mergo"
)

type Config struct {
	Host string
	Port int
	TLS  bool
}

func main() {
	// Assertion 1: mergo.Merge merges non-zero fields from a source struct into zero-value fields of a destination struct pointer without overwriting existing non-zero fields
	dest1 := Config{
		Port: 9000,
	}
	src1 := Config{
		Host: "localhost",
		Port: 8080,
		TLS:  true,
	}
	if err := mergo.Merge(&dest1, src1); err != nil {
		fmt.Fprintf(os.Stderr, "assertion 1 failed: unexpected error: %v\n", err)
		os.Exit(1)
	}
	if dest1.Host != "localhost" || dest1.Port != 9000 || dest1.TLS != true {
		fmt.Fprintf(os.Stderr, "assertion 1 failed: expected Host=localhost, Port=9000, TLS=true; got Host=%s, Port=%d, TLS=%t\n", dest1.Host, dest1.Port, dest1.TLS)
		os.Exit(1)
	}

	// Assertion 2: mergo.Merge populates missing keys in a destination map from a source map while preserving existing destination keys
	destMap := map[string]string{
		"env":  "production",
		"tier": "backend",
	}
	srcMap := map[string]string{
		"tier":   "frontend",
		"region": "us-west",
	}
	if err := mergo.Merge(&destMap, srcMap); err != nil {
		fmt.Fprintf(os.Stderr, "assertion 2 failed: unexpected error: %v\n", err)
		os.Exit(1)
	}
	if destMap["env"] != "production" || destMap["tier"] != "backend" || destMap["region"] != "us-west" {
		fmt.Fprintf(os.Stderr, "assertion 2 failed: map content mismatch: %v\n", destMap)
		os.Exit(1)
	}

	// Assertion 3: mergo.Merge returns an error when destination is not a pointer
	destNonPtr := Config{}
	srcNonPtr := Config{Host: "example.com"}
	if err := mergo.Merge(destNonPtr, srcNonPtr); err == nil {
		fmt.Fprintf(os.Stderr, "assertion 3 failed: expected error when dst is not a pointer, got nil\n")
		os.Exit(1)
	}

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

オリジンシーダー

匿名