CodeSampleX

샘플

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

검증된 샘플 — golang github.com/imdario/mergo v0.3.12: Config. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: mergo.Config controls struct merge…

sha256:65020a3ceb5d34678951f2fac262abb91dbc2b2b59a99346cd1bcf310fc1cf1f

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

컨트랙트

  1. mergo.Config controls struct merge behavior including Overwrite and AppendSlice options
  2. mergo.Config functional options apply custom configuration to merge non-zero fields and append slices

파일

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • mergoconfig.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.Config 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.Config

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:24407bf89e89bec3ae555598c2e94e899b7a8d387d72230de04681d504405d4b","contract":["mergo.Config controls struct merge behavior including Overwrite and AppendSlice options","mergo.Config functional options apply custom configuration to merge non-zero fields and append slices"],"goal":"verify github.com/imdario/mergo.Config 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.Config"]},"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.Config"],"verifierAdapter":"golang@1"}
go.mod
module example.com/mergo-config-sample

go 1.22.0

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/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
mergoconfig.go
package mergoconfig

import (
	"github.com/imdario/mergo"
)

// AppConfig represents application configuration settings.
type AppConfig struct {
	Host    string
	Port    int
	Tags    []string
	Enabled bool
}

// MergeWithConfigOptions merges src into dst using mergo functional options on mergo.Config.
func MergeWithConfigOptions(dst *AppConfig, src AppConfig, opts ...func(*mergo.Config)) error {
	return mergo.Merge(dst, src, opts...)
}

// MergeWithConfig merges src into dst applying explicit mergo.Config settings.
func MergeWithConfig(dst *AppConfig, src AppConfig, cfg mergo.Config) error {
	applyConfig := func(c *mergo.Config) {
		c.Overwrite = cfg.Overwrite
		c.AppendSlice = cfg.AppendSlice
		c.TypeCheck = cfg.TypeCheck
		c.Transformers = cfg.Transformers
	}
	return mergo.Merge(dst, src, applyConfig)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/imdario/mergo.Config 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.Config"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	sample "example.com/mergo-config-sample"
	"github.com/imdario/mergo"
)

func main() {
	// Assertion 1: Default merge behavior (Config with Overwrite=false, AppendSlice=false)
	// Preserves non-zero destination fields and populates zero-value fields.
	dst1 := sample.AppConfig{
		Host: "localhost",
		Port: 0,
		Tags: []string{"web"},
	}
	src1 := sample.AppConfig{
		Host: "example.com",
		Port: 8080,
		Tags: []string{"api"},
	}
	if err := sample.MergeWithConfigOptions(&dst1, src1); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: default merge failed: %v\n", err)
		os.Exit(1)
	}
	if dst1.Host != "localhost" || dst1.Port != 8080 || len(dst1.Tags) != 1 || dst1.Tags[0] != "web" {
		fmt.Fprintf(os.Stderr, "FAIL: default merge unexpected values: %+v\n", dst1)
		os.Exit(1)
	}

	// Assertion 2: Config.Overwrite = true via mergo.WithOverride
	// Overwrites existing destination fields with source values.
	dst2 := sample.AppConfig{
		Host: "localhost",
		Port: 3000,
	}
	src2 := sample.AppConfig{
		Host: "example.com",
		Port: 9000,
	}
	if err := sample.MergeWithConfigOptions(&dst2, src2, mergo.WithOverride); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: WithOverride merge failed: %v\n", err)
		os.Exit(1)
	}
	if dst2.Host != "example.com" || dst2.Port != 9000 {
		fmt.Fprintf(os.Stderr, "FAIL: WithOverride unexpected values: %+v\n", dst2)
		os.Exit(1)
	}

	// Assertion 3: Config.AppendSlice = true via mergo.WithAppendSlice
	// Concatenates slices instead of replacing or ignoring.
	dst3 := sample.AppConfig{
		Tags: []string{"first", "second"},
	}
	src3 := sample.AppConfig{
		Tags: []string{"third"},
	}
	if err := sample.MergeWithConfigOptions(&dst3, src3, mergo.WithAppendSlice); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: WithAppendSlice merge failed: %v\n", err)
		os.Exit(1)
	}
	if len(dst3.Tags) != 3 || dst3.Tags[0] != "first" || dst3.Tags[1] != "second" || dst3.Tags[2] != "third" {
		fmt.Fprintf(os.Stderr, "FAIL: WithAppendSlice unexpected slice: %+v\n", dst3.Tags)
		os.Exit(1)
	}

	// Assertion 4: Direct mergo.Config struct passed to configure merge
	// Configures both Overwrite and AppendSlice simultaneously.
	cfg4 := mergo.Config{
		Overwrite:   true,
		AppendSlice: true,
	}
	dst4 := sample.AppConfig{
		Host: "old-host",
		Port: 80,
		Tags: []string{"alpha"},
	}
	src4 := sample.AppConfig{
		Host: "new-host",
		Port: 443,
		Tags: []string{"beta"},
	}
	if err := sample.MergeWithConfig(&dst4, src4, cfg4); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: MergeWithConfig failed: %v\n", err)
		os.Exit(1)
	}
	if dst4.Host != "new-host" || dst4.Port != 443 || len(dst4.Tags) != 2 || dst4.Tags[0] != "alpha" || dst4.Tags[1] != "beta" {
		fmt.Fprintf(os.Stderr, "FAIL: MergeWithConfig unexpected values: %+v\n", dst4)
		os.Exit(1)
	}

	// Assertion 5: Custom functional option modifying *mergo.Config directly
	customOpt := func(c *mergo.Config) {
		c.Overwrite = true
		c.TypeCheck = true
	}
	dst5 := sample.AppConfig{
		Host: "custom-old",
	}
	src5 := sample.AppConfig{
		Host: "custom-new",
	}
	if err := mergo.Merge(&dst5, src5, customOpt); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: custom Config option failed: %v\n", err)
		os.Exit(1)
	}
	if dst5.Host != "custom-new" {
		fmt.Fprintf(os.Stderr, "FAIL: custom Config option unexpected Host: %s\n", dst5.Host)
		os.Exit(1)
	}

	fmt.Println("PASS: github.com/imdario/mergo.Config contract verified successfully")
}

오리진 시더

익명