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 ¶
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.
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 (*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.