Public API: - Unmarshal(dst, opts...) - UnmarshalPrefix(dst, prefix, opts...) - AsMap() / AsMapPrefix(prefix) - Options: WithTrim, WithWeaklyTyped, WithTagName, WithDecodeHook Merges three divergent in-repo copies (ai-fabric/pkg/env, markets-platform/TP-general-code/pkg/system, and the var/agents/issue-* snapshots), adds error wrapping, prefix filter, and pluggable hooks. 15 pure-Go unit tests, no synthetic mocks, lint clean. Extracted per inventar/docs/asr/ASR-0008-ai-fabric-audit.md.
1.6 KiB
1.6 KiB
AGENTS.md — go-env
This module is part of the eSlider go-* library standard (inventar ASR-0008).
Purpose
Decode os.Environ() into Go structs. Extracted from
produktor.io/ai-fabric/pkg/env on 2026-04-24.
Public API surface
env.Unmarshal(dst any, opts ...Option) errorenv.UnmarshalPrefix(dst any, prefix string, opts ...Option) errorenv.AsMap() map[string]anyenv.AsMapPrefix(prefix string) map[string]any- Options:
WithTrim,WithWeaklyTyped,WithTagName,WithDecodeHook
Breaking changes require a new major version tag (SemVer). Internal helpers
(asMapFromEnviron, trimStringHook, insertPath) are unexported and
may change without notice.
Testing policy
Follows the eSlider "no synthetic mocks" policy:
- Unit tests (
env_test.go): pure inputs only. We pass syntheticenvironslices toasMapFromEnviron— that is not a mock of anything external; it's the normal way to test a pure function. Uset.SetenvforUnmarshal*happy-path tests since Go'sos.Environlookup is well-defined local behaviour, not a vendor protocol. - No
httptest— this library has no HTTP surface. - No integration-test build tag — everything is in-process.
Checklist before release
cd go-env
go mod tidy
go vet ./...
go test -race -count=1 ./...
golangci-lint run --timeout 5m # same preset as go-onlyoffice
Bump CHANGELOG.md, tag vX.Y.Z, push.
Related
inventar/docs/asr/ASR-0008.md— Go library module conventionsinventar/docs/asr/ASR-0008-ai-fabric-audit.md— why this module existsgo-onlyoffice/AGENTS.md— reference for the eSlider library template