Repository navigation
Conversation
- add env/expand.go implementing ${NAME}, ${NAME:default} and
${NAME:-default} substitution with quote-stripped defaults
- fix ${VAR:default} silently resolving to empty: envsubst treated the
single-colon form as a bash substring offset, so numeric defaults
like ${PORT:8080} never applied
- fix keys containing digits failing to resolve: lookup falls back from
the raw name to the keyHandler-normalized name (T2HOST -> T2_HOST)
- drop github.com/a8m/envsubst dependency
…d Or getters
- centralize env key resolution in lookupEnv: raw name, keyHandler-normalized
name, then normalized uppercase name; fixes lowercase references of
digit-renamed keys (${sha256sum} now finds SHA256_SUM)
- Get/Lookup now resolve raw-exported keys without Reload, matching Expand;
Delete unsets every stored spelling so renamed vars are actually removed
- add GetBoolOr/GetIntOr/GetFloatOr with explicit defaults instead of -1/false
sentinels
- document Reload's process-wide rewriting side effect in doc comment and
READMEs
- fix documented-but-unimplemented ${env.VAR} syntax in config docs (real
syntax is the CEL env("VAR") function)
Fast Fallback has been enabled by default since Go 1.12; the field is deprecated and fails staticcheck SA1019 on CI.
Upstream github.com/ettle/strcase (v0.2.0) is no longer maintained. Copy the sources the repo actually uses into internal/strcase, keeping the package API frozen; upstream MIT license text and copyright notice are preserved in internal/strcase/LICENSE as the license requires. Only env/util.go imported the package; behavior is verified by the vendored upstream test suite (caser/strcase/unicode tests) plus the existing env/config tests.
3 tasks done
The codegen plugin and protoutils test only used ToCamel/ToSnake; switch to the vendored internal/strcase (ToPascal/ToSnake). Outputs are identical for conventional proto naming; for names with digits or acronyms the new output is more idiomatic (APIKey -> ApiKey instead of Apikey).
… to workspace guide
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Removes three unmaintained/problematic external dependencies and fixes long-standing bugs in environment variable substitution:
github.com/a8m/envsubst→ replaced by a built-in expander (env/expand.go), fixing default-value and digit-key resolution bugs.github.com/ettle/strcase(upstream unmaintained) → vendored intointernal/strcasewith its MIT license preserved.github.com/iancoleman/strcase→ removed; the codegen plugin now uses the vendoredinternal/strcase.Changes
envsubst removal & substitution fixes (5c29c29)
${VAR:default}silently resolving to empty. envsubst implements bash parameter expansion, where the single-colon form is a substring offset, not a default value.${PORT:8080}withPORTunset resolved to an empty string, so numeric defaults likeport: ${PORT:8080}never applied (loaded as0).keyHandlerrenames keys at digit-to-uppercase boundaries onenv.Set/Reload(T2HOSTis stored asT2_HOST,SHA256SUMasSHA256_SUM), while substitution looked up the raw name only, so declared values were never found.env/expand.go):${NAME}/$NAME— env value, empty when unset${NAME:default}/${NAME:-default}— default when unset or empty; everything after the first:is the default (inner colons kept, surrounding quotes stripped)patch_envsvalues keep priority over inline defaults (existing behavior preserved)env key-resolution hardening (b9072ef)
raw name→keyHandler(name)→keyHandler(ToUpper(name))) shared byExpand,Get/getValandLookup, so lowercase references of renamed digit keys resolve too (${sha256sum}findsSHA256_SUM).Deleteunsets every stored spelling of a key, so variables saved under a renamed key are actually removed.GetBoolOr/GetIntOr/GetFloatOr— explicit defaults on unset/empty/parse-error instead of-1/falsesentinels.Reload()blast radius: it rewrites the whole process environment in place; warning added to doc comment and READMEs.${env.VAR}syntax in config docs (real syntax is the CELenv("VAR")function).resty lint fix (0f496e3)
net.Dialer.DualStackincomponent/resty(staticcheck SA1019, pre-existing CI lint failure).strcase vendoring (a54c794)
github.com/ettle/strcasev0.2.0 intointernal/strcase(caser, split, convert, initialisms, unicode helpers) with upstream tests kept as the behavioral spec; MIT license text and copyright preserved ininternal/strcase/LICENSE.env/util.goswitched to the internal path;go mod tidydrops the dependency. No behavioral change (key normalization verified unchanged).iancoleman/strcase removal (4f18b58)
cmds/protoc-gen-go-errors2and theprotoutilstest only usedToCamel/ToSnake; switched to the vendoredinternal/strcase(ToPascal/ToSnake). Output is identical for conventional proto naming; names with digits or acronyms now produce more idiomatic Go (APIKey->ApiKeyinstead ofApikey).Also carries
refactor: adopt modern Go stdlib APIs across packages(b82d7e2): mechanicalreflect.TypeOf→reflect.TypeFormodernization committed on this branch.Supersedes #65.
Behavior changes
${VAR:default}now applies the default when the variable is unset or empty (previously silently empty). Bash advanced expansions (:?,#len, substring,//replace) are no longer supported byenv.Expand— none were used in the repo or documented.Get/Lookup/Deleteresolve additional key spellings (raw name first); keys stored under exactly one spelling keep their values, so existing callers are unaffected unless a raw and a normalized key coexist.keyHandler's renaming itself (case-asymmetric) — deferred to v3.Testing
go test ./internal/strcase/)env/expand_test.go(24 cases),env/api_test.go(raw fallback, typed getters, LoadFiles, Expand×Reload),config/expand_test.go(4 end-to-end regressions)go test -race ./env/ ./config/and full suitego test ./...pass; golden config tests unchangedgo vetclean;golangci-lint runrepo-wide: 0 issues