Documentation
¶
Overview ¶
Package jsonmask provides functionality to mask JSON data based on field metadata.
This file contains default maskers that are used to mask the JSON data. All functions have the same signature: func(string) []byte. The input string is a JSON string that represents a single value (with quotes).
Index ¶
- Constants
- Variables
- func Email(email string) []byte
- func InitialChar(s string) []byte
- func Lower(s string) []byte
- func Null(s string) []byte
- func PrefixFn(length int, addEllipsis bool) func(string) []byte
- func Truncate(s string) []byte
- func Upper(s string) []byte
- func Zero(s string) []byte
- type JsonMaskerImpl
- type Rule
- type StructMaskRules
Constants ¶
const DefaultStructFieldTag = "mask"
DefaultStructFieldTag is a default tag name for struct fields.
Variables ¶
var (
ErrInvalidInput = errors.New("input must be a struct")
)
Error definitions
Functions ¶
func InitialChar ¶
InitialChar returns the first character of the input string in uppercase.
func PrefixFn ¶
PrefixFn returns a function that prefixes the input string with the specified length.
Types ¶
type JsonMaskerImpl ¶
type JsonMaskerImpl struct {
// contains filtered or unexported fields
}
JsonMaskerImpl provides functionality to mask JSON data based on field metadata and custom masking functions.
func NewWithMaskTag ¶
func NewWithMaskTag(tag string) *JsonMaskerImpl
NewWithMaskTag creates a new instance of JsonMaskerImpl with a custom tag name.
func (*JsonMaskerImpl) AddFunc ¶
func (jm *JsonMaskerImpl) AddFunc(name string, f func(string) []byte)
AddFunc adds a masking function associated with a name.
func (*JsonMaskerImpl) Mask ¶
func (jm *JsonMaskerImpl) Mask(data []byte, smr StructMaskRules) ([]byte, error)
Mask applies masking to JSON based on the given rules.
func (*JsonMaskerImpl) ParseStruct ¶
func (jm *JsonMaskerImpl) ParseStruct(src any) StructMaskRules
ParseStruct extracts metadata fields from the given structure based on the provided tag.
type Rule ¶
type Rule struct {
// Path is a JSON path to the field.
Path string
// Action is a value of the mask tag.
// It can be a name of a custom masking function or "-" to delete the field.
Action string
// contains filtered or unexported fields
}
Rule holds metadata for a single field of a structure.
type StructMaskRules ¶
type StructMaskRules struct {
Rules []Rule
}
StructMaskRules holds metadata for a structure.