Ejemplo
github.com/spf13/viper 1.21.0: Pin spf13/viper's configuration precedence order and the env, IsSet and case-folding traps around it, without reading a config file from disk
Muestra verificada para golang github.com/spf13/viper 1.21.0: Pin spf13/viper's configuration precedence order and the env, IsSet and case-folding traps…
sha256:ea36c1c79c3a4263305e79d2403494634711a275d2fd41a2d8df834ac7e9101b
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
- 2
- Claves de firma que lo compilaron
- 2
Entorno declarado
go 1.26 linux x64 go 1.26 go go
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| go 1.26 · linux alpine/x64 · docker ed25519:a2ec939a4c60e243 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1 |
2026-08-14 |
| go 1.26 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1 |
2026-08-18 |
Caso
HOW- Objetivo
- Pin spf13/viper's configuration precedence order and the env, IsSet and case-folding traps around it, without reading a config file from disk
- Símbolos
-
- viper.New
- viper.SetDefault
- viper.Set
- viper.BindPFlag
- viper.AutomaticEnv
- viper.SetEnvPrefix
- viper.SetEnvKeyReplacer
- viper.BindEnv
- viper.AllowEmptyEnv
- viper.ReadConfig
- viper.AddRemoteProvider
- viper.RemoteConfig
- viper.ReadRemoteConfig
- viper.IsSet
- viper.Get
- viper.AllKeys
- viper.Unmarshal
- viper.ExperimentalBindStruct
- Entorno
- go 1.26
- Creado
- 2026-08-14T13:24:24Z
Contrato
- assert the documented ladder top down by writing the same key at every rung at once: explicit Set beats a changed flag beats env beats config file beats key/value store beats default, each rung checked with everything below it populated
- assert the key/value rung is reachable offline through viper.RemoteConfig, whose interface type is unexported but whose three methods are not, so the one rung nobody ever sees is observable without an etcd server
- assert a bound flag only sits at flag height once pflag records it as Changed, and that its default is consulted last of all, below SetDefault, so a flag default loses to a config file
- assert IsSet searches with that flag-default pass switched off, so it returns false for a key whose Get returns the flag's default
- assert AutomaticEnv computes the name as uppercase(prefix + underscore + key) by exporting the literal name CSX_LOG.LEVEL and watching a dotted key find it, which no shell could have exported
- assert that without SetEnvKeyReplacer the expected CSX_LOG_LEVEL is never consulted for the key log.level, and that installing the replacer reaches it
- assert the underscore between prefix and key is added by viper, so SetEnvPrefix("csx_") looks up CSX__LOG_LEVEL
- assert the replacer runs over the finished name rather than the key alone, so SetEnvPrefix("csx.app") with a dot replacer looks up CSX_APP_LOG_LEVEL
- assert an env var exported empty is treated as unset and falls through to the config file, until AllowEmptyEnv(true) makes the empty string a value that IsSet agrees is set
- assert BindEnv with one argument means prefix plus key, while a second argument is the env name verbatim with no prefix, no uppercasing and no replacer
- assert Get, GetString, GetInt, GetBool and GetDuration return zero values rather than errors on a missing key, so a typo is indistinguishable from a zero, and IsSet is the only thing that tells them apart
- assert, measured, that IsSet is true for a key that only has a default, while Set(key, nil) is invisible to the search and does not even shadow the default underneath it
- assert keys are case-insensitive and stored folded: Get agrees across spellings, AllKeys reports only the lower-case form, and a document's keys are folded on read while its values are left alone
- assert Unmarshal enumerates AllKeys rather than searching per key, so a value AutomaticEnv makes Get return is absent from both AllSettings and the struct, and that either a default for the key or viper.ExperimentalBindStruct brings it back
Archivos
- csx.json
- go.mod
- go.sum
- src/config.go
- test/main.go