jsonmask

package
v1.25.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 5 Imported by: 1

Documentation

Overview

Package jsonmask masks sensitive values in JSON documents according to struct tags.

A field tagged `mask:"-"` is removed from the document. A field tagged with any other non-empty value is replaced by the result of the function registered under that name with AddFunc, or by "***" when no such function is registered. A tagged field is a leaf: when its type is a struct, a pointer or a slice, the whole value is masked or removed, its own fields are not visited.

Untagged fields of struct, pointer to struct, slice and array types are visited, so tags of nested structures and of array elements are honoured. Recursive types are supported. Maps and interface values are not visited. Rules are applied only to values present in the document: a field omitted by `omitempty` is not added.

Index

Constants

View Source
const DefaultMask = "***"

DefaultMask replaces values tagged with a function name that is not registered with AddFunc.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

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

Field is a masking rule applied to the JSON value found at a path.

type Fields

type Fields []Field

Fields holds masking rules of a type, built by RawJsonMask.Fields.

func (Fields) HasRules added in v1.25.0

func (f Fields) HasRules() bool

HasRules reports whether masking with these rules can change a document.

type RawJsonMask

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

RawJsonMask masks fields of JSON documents by rules read from struct tags. Masking functions are registered by name with AddFunc.

func New

func New() *RawJsonMask

New returns a RawJsonMask without masking functions.

func (*RawJsonMask) AddFunc

func (jm *RawJsonMask) AddFunc(name string, f func(string) string)

AddFunc adds masking function associated with name.

func (*RawJsonMask) Fields

func (jm *RawJsonMask) Fields(src any, tag string) Fields

Fields returns masking rules of the type of src, read from the struct tag tag. src may be any value, including nil, a typed nil pointer, a struct, a slice or a pointer to a slice; types without tagged fields give empty rules.

func (*RawJsonMask) Mask

func (jm *RawJsonMask) Mask(src []byte, fields Fields) ([]byte, error)

Mask returns a copy of src with fields masked according to rules.

Jump to

Keyboard shortcuts

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