credentials¶
Storage-mode abstraction for user-supplied secrets in Go CLIs — the config
records how a secret is stored (an env-var name, a keychain reference, or
a literal), never a plaintext secret unless you explicitly ask for it. A
pluggable Backend sits behind the modes, and the OS keychain is an auditable
opt-in.
gitlab.com/phpboyscout/go/credentials is the credential-storage layer extracted
from go-tool-base, where it backs
every setup wizard, doctor check, and runtime resolver. It answers one question
consistently — where does this secret live, and how do I get it back? — so a tool
does not re-implement the same env/keychain/literal switch at every call site.
Why¶
- Framework-free. The core's only dependencies are
cockroachdb/errorsandgolang.org/x/term(for the stdlib prompt's masked entry). No config framework, no TUI, no go-tool-base — adepfootprint_test.goguard enforces the boundary. - Secrets stay out of config by default.
ModeEnvVarrecords a variable name;ModeKeychainrecords aservice/accountreference. OnlyModeLiteralwrites the secret itself — and it is refused underCI=true. - Auditable keychain opt-out. The go-keyring backend lives in the optional
credentials/keychainsubpackage. Omit its blank import and the linker strips go-keyring and all keychain IPC from your binary — provable via SBOM. See the keychain opt-out. - UI-agnostic capture, overridable. A
Prompterseam captures the interactive input; a stdlib default ships in the box, and a tool swaps in a themed TUI so prompts match the rest of its UX.
Where next¶
- Getting started — capture and resolve a credential end to end in a few lines.
- Choose a storage mode — env-var reference vs OS keychain vs literal, and when to use each.
- Enable OS-keychain storage — one blank import, plus the regulated-build opt-out.
- Implement a custom backend
— plug in Vault, AWS SSM, or 1Password by satisfying
Backend. - Theme the prompts — override the stdlib prompter with your own TUI.
- Trust model — what each mode does and does not protect against.
- API reference — every exported symbol, its defaults, and what it does when it fails.
Reference¶
| Page | Answers |
|---|---|
| API reference | What does this function do, what does it default to, and what does it return when it fails? |
| Storage modes | What are the exact Mode values, and which modes may I offer? |
| Errors | Which error is this, and should I fall through or surface it? |
| Configuration | What does the module read from the environment, and what happens when it is wrong? |
| Limitations | Is that supported? Usually the answer is no, and this page says which. |
Generated Go signatures and doc comments are on pkg.go.dev; the pages above add the behaviour a signature does not show.
Further reading¶
The blog carries a curated route through this subject: Building a command-line tool in Go collects everything written about it, ordered so you can start at the beginning rather than newest-first.
Ask phpbotscout

He answers questions about the projects over on the Discord, citing the docs where they already cover it, and offering to raise an issue where they don't. Bring a bug, an idea, or a questionable engineering decision.