Documentation
¶
Overview ¶
Package secret provides a masked string type for passwords, tokens and other sensitive values. A struct or config that carries a Secret never leaks it when formatted, logged, or serialized; the real value is obtained only through an explicit Reveal call.
The package has no external dependencies, so infrastructure libraries can use Secret in their (source-agnostic) Config structs without pulling in a config or env-parsing dependency.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Secret ¶
type Secret string
Secret is a sensitive string that masks itself everywhere it could be exposed: fmt verbs (%v/%s/%+v/%#v), encoding/json and encoding/text (via MarshalText), and log/slog (via LogValue). An empty Secret renders as empty.
The underlying value is retrieved only with Reveal, which makes every real use greppable.
func (Secret) MarshalText ¶
MarshalText masks the value for encoding/json, TOML and any other encoding.TextMarshaler-based encoder, so serializing a struct never leaks it.
func (Secret) Reveal ¶
Reveal returns the underlying secret value. Call it only where the real value is genuinely required (e.g. building a connection); never log the result.
func (*Secret) UnmarshalText ¶
UnmarshalText fills the Secret with the raw bytes, so an env or text decoder (for example a config loader reading a value out of the environment) can set it. It is deliberately asymmetric with MarshalText: the real value is read in here, while every outward representation stays masked.