scrub

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package scrub redacts sensitive data from structured values and slog records.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

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

Handler is a slog handler that redacts sensitive attributes before logging.

func NewHandler

func NewHandler(next slog.Handler, opts ...Option) *Handler

NewHandler wraps next with a redacting slog handler.

func (*Handler) Enabled

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

Enabled reports whether records at level should be logged.

func (*Handler) Handle

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

Handle redacts record attributes before delegating to the wrapped handler.

func (*Handler) WithAttrs

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

WithAttrs returns a handler with redacted attributes attached.

func (*Handler) WithGroup

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

WithGroup returns a handler with name added to subsequent attribute keys.

type Option

type Option func(*Redactor)

Option configures a Redactor.

func WithKeys

func WithKeys(keys ...string) Option

WithKeys adds sensitive keys to a redactor.

func WithReplacement

func WithReplacement(replacement string) Option

WithReplacement changes the replacement value used for redacted data.

type Redactor

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

Redactor redacts sensitive values from structured data.

func New

func New(opts ...Option) *Redactor

New creates a redactor with Ohm's default sensitive keys.

func (*Redactor) Any

func (r *Redactor) Any(key string, value any) any

Any returns a scrubbed copy of value when the value is a supported structured type.

func (*Redactor) Attr

func (r *Redactor) Attr(attr slog.Attr) slog.Attr

Attr returns a scrubbed slog attribute.

func (*Redactor) SensitiveKey

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

SensitiveKey reports whether key should be redacted.

type Sensitive

type Sensitive struct {
	Value any
}

Sensitive marks a value that must always be redacted.

func Mark

func Mark(value any) Sensitive

Mark returns a value wrapper that is always redacted.

Jump to

Keyboard shortcuts

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