redact

package
v0.0.655 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package redact provides a self-redacting string type for values that must stay usable in code but must never appear in logs or other rendered output (for example signed blobstore URLs, which are bearer credentials).

Index

Constants

View Source
const Placeholder = "<redacted>"

Placeholder is what a Secret renders as in place of its value.

Variables

This section is empty.

Functions

This section is empty.

Types

type Secret

type Secret string

Secret is a string that redacts itself on the usual logging paths: every fmt verb (via Format), Stringer/GoString, and slog when the Secret is the logged value (via LogValue). The real value is available only via Reveal().

Boundary — JSON: JSON (un)marshaling is intentionally left as the default string behaviour so secrets still round-trip for functional use; a Secret marshals to its real value. Consequently a Secret nested in a struct that is serialized with encoding/json is NOT redacted. In particular slog.JSONHandler marshals an enclosing struct passed as a log value with encoding/json, which bypasses Format and LogValue and emits the real value (slog.TextHandler and fmt are unaffected). Do not log JSON-serialized structures that contain a Secret — log the Secret directly, use a text/fmt-based logger, or convert the enclosing value to a logging-safe form. Do not add a redacting MarshalJSON here: it would break the required round-trip.

func (Secret) Format

func (Secret) Format(f fmt.State, _ rune)

Format implements fmt.Formatter, which fmt consults for every verb, so the value is redacted no matter how it is printed (%v, %s, %q, %x, ...).

func (Secret) GoString

func (Secret) GoString() string

GoString implements fmt.GoStringer so %#v is redacted too.

func (Secret) LogValue

func (Secret) LogValue() slog.Value

LogValue implements slog.LogValuer.

func (Secret) Reveal

func (s Secret) Reveal() string

Reveal returns the underlying secret value. Never pass the result to a logger.

func (Secret) String

func (Secret) String() string

String implements fmt.Stringer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL