redact

package
v0.4.0 Latest Latest
Warning

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

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

Documentation

Overview

Package redact removes secret-looking values from text before it reaches evidence rings, spools, transmission, or diagnostics (PRD L6, 10).

Index

Constants

View Source
const Placeholder = "<redacted>"

Placeholder replaces every redacted value.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// ExtraKeys are additional key names whose values are always redacted.
	ExtraKeys []string
	// ExtraPatterns are additional regular expressions whose matches are replaced.
	ExtraPatterns []string
}

Config customizes a Redactor.

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler is a slog.Handler that redacts messages and string attributes before any sink.

func NewHandler

func NewHandler(next slog.Handler, r *Redactor) *Handler

NewHandler wraps next.

func (*Handler) Enabled

func (h *Handler) Enabled(ctx context.Context, l slog.Level) bool

func (*Handler) Handle

func (h *Handler) Handle(ctx context.Context, rec slog.Record) error

func (*Handler) WithAttrs

func (h *Handler) WithAttrs(as []slog.Attr) slog.Handler

func (*Handler) WithGroup

func (h *Handler) WithGroup(name string) slog.Handler

type Redactor

type Redactor struct {
	// contains filtered or unexported fields
}

Redactor applies an ordered list of redaction rules.

func Default

func Default() *Redactor

Default returns the shared default Redactor.

func New

func New(cfg Config) (*Redactor, error)

New builds a Redactor with the default rules plus cfg.

func (*Redactor) IsSecretKey

func (r *Redactor) IsSecretKey(key string) bool

IsSecretKey reports whether a field or label name always holds a secret.

func (*Redactor) KeyValue

func (r *Redactor) KeyValue(key, value string) string

KeyValue redacts value when key names a secret, and otherwise redacts patterns inside value.

func (*Redactor) String

func (r *Redactor) String(s string) string

String redacts secret-looking values in s.

Jump to

Keyboard shortcuts

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