CodeSampleX

Exemple

github.com/spf13/viper v1.21.0: Show that delimiter-aware key lookup state is preserved when taking a Viper sub-tree.

Échantillon vérifié pour golang github.com/spf13/viper v1.21.0: Show that delimiter-aware key lookup state is preserved when taking a Viper sub-tree. Le…

sha256:d94c20e315074af42aec87c2953790acf56055ab6f0dd3590e9fba8d85eb1cc4

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
5
Clés de signature qui l’ont compilé
1
Environnement déclaré go linux x64 go go go

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
go 1.26 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1
2026-08-16
go 1.26 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 SKIPPED compile:SKIPPED · contract:SKIPPED · load:SKIPPED · resolve:FAIL
CONTAINER_RUN · golang@1
2026-08-18
go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 SKIPPED compile:SKIPPED · contract:SKIPPED · load:SKIPPED · resolve:FAIL
CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f…
2026-09-08
go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 SKIPPED compile:SKIPPED · contract:SKIPPED · load:SKIPPED · resolve:FAIL
CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f…
2026-09-08
go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 SKIPPED compile:SKIPPED · contract:SKIPPED · load:SKIPPED · resolve:FAIL
CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f…
2026-09-08

Cas

HOW
Objectif
Show that delimiter-aware key lookup state is preserved when taking a Viper sub-tree.
Paquets
Symboles
  • github.com/spf13/viper.New
  • github.com/spf13/viper.NewWithOptions
  • github.com/spf13/viper.KeyDelimiter
  • github.com/spf13/viper.Viper.Sub
  • github.com/spf13/viper.Viper.GetString
Environnement
go
Créé
2026-08-16T12:32:36Z

Contrat

  1. A Viper instance using delimiter `::` returns `db.local` for `service::db::host`, and `Sub("service")` also returns `db.local` for `db::host`.
  2. When delimiter-specific lookup on the sub-tree works, it proves `Sub()` preserved lookup behavior instead of silently falling back to parentless key parsing.

Fichiers

  • NOTES.md
  • csx.json
  • go.mod
  • go.sum
  • viper_subtree_delimiter_test.go

Télécharger l’artefact source (tar.gz)

Code source

NOTES.md
search_known_solution returned a REFERENCE_ONLY hit: `case:sha256:49a00062ac22ba403d7fad6003e0e7adb4f024adef22bf71a527a801c0d9a459` (environment precedence/env-name traps).
In the older behavior, `Sub(\"service\")` dropped the custom delimiter, so `Sub(\"service\").GetString(\"db::host\")` returned an empty value instead of `db.local` (silent logic gap rather than a hard error).
csx.json
{"case":{"believed":"A `Sub()` call drops a custom key delimiter to the default delimiter, so a value set under `service::db::host` cannot be read from `sub.GetString(\"db::host\")`.","caseId":"case:sha256:4084250b6fbe92a771fe38500ac8a91c92423a7ed48bea0b9b833931efbb6140","contract":["A Viper instance using delimiter `::` returns `db.local` for `service::db::host`, and `Sub(\"service\")` also returns `db.local` for `db::host`.","When delimiter-specific lookup on the sub-tree works, it proves `Sub()` preserved lookup behavior instead of silently falling back to parentless key parsing."],"goal":"Show that delimiter-aware key lookup state is preserved when taking a Viper sub-tree.","kind":"HOW","packages":["pkg:golang/github.com/spf13/viper@1.21.0"],"schemaVersion":1,"symbols":["github.com/spf13/viper.New","github.com/spf13/viper.NewWithOptions","github.com/spf13/viper.KeyDelimiter","github.com/spf13/viper.Viper.Sub","github.com/spf13/viper.Viper.GetString"]},"contractCommand":["go","test","./..."],"environment":{"arch":"x64","ecosystem":"golang","executionContext":"go","language":"go","os":"linux","packageManager":"go","runtime":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/spf13/viper@1.21.0"],"schemaVersion":1,"symbols":["github.com/spf13/viper.New","github.com/spf13/viper.NewWithOptions","github.com/spf13/viper.KeyDelimiter","github.com/spf13/viper.Viper.Sub","github.com/spf13/viper.Viper.GetString"],"verifierAdapter":"golang@1"}
go.mod
module example.com/viper-subtree-delimiter

go 1.23.0

require github.com/spf13/viper v1.21.0

require (
	github.com/fsnotify/fsnotify v1.9.0 // indirect
	github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
	github.com/pelletier/go-toml/v2 v2.2.4 // indirect
	github.com/sagikazarmark/locafero v0.11.0 // indirect
	github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
	github.com/spf13/afero v1.15.0 // indirect
	github.com/spf13/cast v1.10.0 // indirect
	github.com/spf13/pflag v1.0.10 // indirect
	github.com/subosito/gotenv v1.6.0 // indirect
	go.yaml.in/yaml/v3 v3.0.4 // indirect
	golang.org/x/sys v0.29.0 // indirect
	golang.org/x/text v0.28.0 // indirect
)
go.sum
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS/6bF9zb3elmeNGIjoY=
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sagikazarmark/locafero v0.11.0 h1:1iurJgmM9G3PA/I+wWYIOw/5SyBtxapeHDcg+AAIFXc=
github.com/sagikazarmark/locafero v0.11.0/go.mod h1:nVIGvgyzw595SUSUE6tvCp3YYTeHs15MvlmU87WwIik=
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 h1:+jumHNA0Wrelhe64i8F6HNlS8pkoyMv5sreGx2Ry5Rw=
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8/go.mod h1:3n1Cwaq1E1/1lhQhtRK2ts/ZwZEhjcQeJQ1RuC6Q/8U=
github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I=
github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg=
github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY=
github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo=
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.21.0 h1:x5S+0EU27Lbphp4UKm1C+1oQO+rKx36vfCoaVebLFSU=
github.com/spf13/viper v1.21.0/go.mod h1:P0lhsswPGWD/1lZJ9ny3fYnVqxiegrlNrEmgLjbTCAY=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
viper_subtree_delimiter_test.go
package viperboundary

import (
	"testing"

	"github.com/spf13/viper"
)

func TestSubInheritsCustomKeyDelimiter(t *testing.T) {
	const delimiter = "::"
	const expected = "db.local"

	v := viper.NewWithOptions(viper.KeyDelimiter(delimiter))
	v.Set("service::db::host", expected)

	if got := v.GetString("service::db::host"); got != expected {
		t.Fatalf("parent key lookup with custom delimiter failed: got %q", got)
	}

	sub := v.Sub("service")
	if got := sub.GetString("db::host"); got != expected {
		t.Fatalf("sub key lookup should inherit delimiter and return %q, got %q", expected, got)
	}
}

Seeder d'origine

csx-seed