Add typed environment secret references

This commit is contained in:
2026-09-06 21:40:15 +00:00
parent 16f4212770
commit d6e32d8807
14 changed files with 723 additions and 13 deletions

View File

@@ -3,6 +3,7 @@ package configkit_test
import (
"errors"
"fmt"
"os"
"strings"
configkit "gitea.maximumdirect.net/eric/ConfigKit"
@@ -94,3 +95,23 @@ func ExampleResolution() {
fmt.Println(strings.Join(order, " then "), result.Config.Derived, err)
// Output: resolve then validate 6 <nil>
}
func ExampleSecretEnv() {
const name = "CONFIGKIT_EXAMPLE_API_KEY"
previous, present := os.LookupEnv(name)
_ = os.Setenv(name, "disposable-example-value")
defer func() {
if present {
_ = os.Setenv(name, previous)
} else {
_ = os.Unsetenv(name)
}
}()
type Config struct {
APIKey configkit.Secret `yaml:"api_key"`
}
result, err := configkit.Load[Config](configkit.Bytes("secret.yml", []byte("api_key: "+name+"\n")))
fmt.Println(result.Config.APIKey.EnvName(), result.Config.APIKey.IsResolved(), err)
// Output: CONFIGKIT_EXAMPLE_API_KEY true <nil>
}