Ejemplo
github.com/imdario/mergo v0.3.12: Map
Muestra verificada para golang github.com/imdario/mergo v0.3.12: Map. El contrato se ejecutó en go 1.26 · linux debian/x64 · docker y pasó.
sha256:091f43b3b9d3d84c3a3363946c0e0dafa3e51f179a903f1b2b3818c1108175d4
Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido.
Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas.
MIT-0
Evidencia de ejecución
El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.
- Base de evidencia
- Contrato firmado aprobado
- Recibos de verificación
- 1
- Claves de firma que lo compilaron
- 1
Entorno declarado
go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| 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 |
Caso
HOW- Objetivo
- verify github.com/imdario/mergo.Map in pkg:golang/github.com/imdario/mergo@v0.3.12
- Paquetes
- Símbolos
-
- github.com/imdario/mergo.Map
- Entorno
- go 1.26.6
- Creado
- 2026-09-04T13:04:07Z
Contrato
- mergo.Map populates empty struct fields from matching map keys
- mergo.Map preserves existing non-zero struct field values by default
- mergo.Map with mergo.WithOverride overwrites existing struct fields with map values
- mergo.Map merges source map entries into destination map without overwriting existing keys by default
- mergo.Map returns an error when destination is not a pointer
Archivos
- PROMPT.md
- csx.json
- go.mod
- go.sum
- sample.go
- spec.json
- test/contract.go
Código fuente
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.Map 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.Map
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.
{"case":{"caseId":"case:sha256:dd95d172f1cb4f1cdaee3bc13d078440c35d0fa86ce0441d20f86898ee5aa3f2","contract":["mergo.Map populates empty struct fields from matching map keys","mergo.Map preserves existing non-zero struct field values by default","mergo.Map with mergo.WithOverride overwrites existing struct fields with map values","mergo.Map merges source map entries into destination map without overwriting existing keys by default","mergo.Map returns an error when destination is not a pointer"],"goal":"verify github.com/imdario/mergo.Map 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.Map"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","runtime":"go","runtimeVersion":"1.26.6","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.Map"],"verifierAdapter":"golang@1"}
module sample
go 1.26.6
require github.com/imdario/mergo v0.3.12
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=
package sample
import (
"errors"
"fmt"
"github.com/imdario/mergo"
)
// Config represents a sample configuration struct to demonstrate map-to-struct merging.
type Config struct {
Host string
Port int
Debug bool
Timeout int
}
// MergeMapToConfig merges a map into a Config struct pointer.
// If override is true, existing non-zero fields in dst are overwritten by non-empty src values.
func MergeMapToConfig(dst *Config, src map[string]interface{}, override bool) error {
if dst == nil {
return errors.New("dst cannot be nil")
}
var opts []func(*mergo.Config)
if override {
opts = append(opts, mergo.WithOverride)
}
if err := mergo.Map(dst, src, opts...); err != nil {
return fmt.Errorf("mergo.Map failed: %w", err)
}
return nil
}
// MergeStringMap merges source map entries into destination map.
// If override is true, existing keys in dst are overwritten by src values.
func MergeStringMap(dst *map[string]interface{}, src map[string]interface{}, override bool) error {
if dst == nil {
return errors.New("dst pointer cannot be nil")
}
var opts []func(*mergo.Config)
if override {
opts = append(opts, mergo.WithOverride)
}
if err := mergo.Map(dst, src, opts...); err != nil {
return fmt.Errorf("mergo.Map failed: %w", err)
}
return nil
}
// DirectMap wraps mergo.Map directly.
func DirectMap(dst, src interface{}, opts ...func(*mergo.Config)) error {
return mergo.Map(dst, src, opts...)
}
{
"schemaVersion": 1,
"goal": "verify github.com/imdario/mergo.Map 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.Map"
]
}
package main
import (
"errors"
"fmt"
"os"
"github.com/imdario/mergo"
"sample"
)
func main() {
// Assertion 1: mergo.Map populates empty struct fields from matching map keys
cfg1 := sample.Config{}
src1 := map[string]interface{}{
"Host": "localhost",
"Port": 8080,
"Debug": true,
}
if err := sample.MergeMapToConfig(&cfg1, src1, false); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: Assertion 1 failed: %v\n", err)
os.Exit(1)
}
if cfg1.Host != "localhost" || cfg1.Port != 8080 || !cfg1.Debug {
fmt.Fprintf(os.Stderr, "FAIL: Assertion 1 failed: unexpected fields: %+v\n", cfg1)
os.Exit(1)
}
// Assertion 2: mergo.Map preserves existing non-zero struct field values by default
cfg2 := sample.Config{
Host: "original.host",
Port: 9000,
Timeout: 30,
}
src2 := map[string]interface{}{
"Host": "new.host",
"Port": 8080,
"Debug": true,
}
if err := sample.MergeMapToConfig(&cfg2, src2, false); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: Assertion 2 failed: %v\n", err)
os.Exit(1)
}
if cfg2.Host != "original.host" || cfg2.Port != 9000 || cfg2.Timeout != 30 || !cfg2.Debug {
fmt.Fprintf(os.Stderr, "FAIL: Assertion 2 failed: default merge altered existing fields: %+v\n", cfg2)
os.Exit(1)
}
// Assertion 3: mergo.Map with mergo.WithOverride overwrites existing struct fields with map values
cfg3 := sample.Config{
Host: "original.host",
Port: 9000,
}
src3 := map[string]interface{}{
"Host": "new.host",
"Port": 8080,
}
if err := sample.MergeMapToConfig(&cfg3, src3, true); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: Assertion 3 failed: %v\n", err)
os.Exit(1)
}
if cfg3.Host != "new.host" || cfg3.Port != 8080 {
fmt.Fprintf(os.Stderr, "FAIL: Assertion 3 failed: override did not update fields: %+v\n", cfg3)
os.Exit(1)
}
// Assertion 4: mergo.Map merges source map entries into destination map without overwriting existing keys by default
dstMap := map[string]interface{}{
"a": 1,
"b": "keep",
}
srcMap := map[string]interface{}{
"b": "overwrite_attempt",
"c": true,
}
if err := sample.MergeStringMap(&dstMap, srcMap, false); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: Assertion 4 failed: %v\n", err)
os.Exit(1)
}
if dstMap["a"] != 1 || dstMap["b"] != "keep" || dstMap["c"] != true {
fmt.Fprintf(os.Stderr, "FAIL: Assertion 4 failed: unexpected map contents: %+v\n", dstMap)
os.Exit(1)
}
// Assertion 5: mergo.Map returns an error when destination is not a pointer
nonPtrCfg := sample.Config{Host: "base"}
errNonPtr := sample.DirectMap(nonPtrCfg, src1)
if errNonPtr == nil {
fmt.Fprintf(os.Stderr, "FAIL: Assertion 5 failed: expected error when passing non-pointer destination, got nil\n")
os.Exit(1)
}
if !errors.Is(errNonPtr, mergo.ErrNonPointerAgument) {
// mergo typically returns ErrNonPointerAgument
// Verify an error is returned
}
fmt.Println("PASS: all mergo.Map contract assertions succeeded")
}
Seeder de origen
anónimo