mask

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2023 License: MIT Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetMasker

func SetMasker(masker *masker.Masker)

SetMasker sets a custom masker instance

func TypeFilter

func TypeFilter(t interface{}, maskTypes ...masker.MType) *typeFilter

TypeFilter returns Type Filter with custom masking type.

Types

type Filter

type Filter interface {
	// ReplaceString is called when checking string type.
	// The argument is the value to be checked, and the return value should be the value to be replaced.
	// If nothing needs to be done, the method should return the argument as is.
	// This method is intended for the case where you want to hide a part of a string.
	ReplaceString(s string) string

	// MaskString is called when checking field, prefix type and tag type.
	// The return value is to be replaced.
	// This method is intended for the case where you want to hide a part of a string.
	MaskString(s string) string

	// ShouldMask is called for all values to be checked.
	// The field name of the value to be checked, and tag value if the structure has `zlog` tag will be passed as arguments.
	// If the return value is false, nothing is done; if it is true, the entire field is hidden.
	// Hidden values will be replaced with the value "[filtered]" if string type.
	ShouldMask(fieldName string, value interface{}, tag string) bool
}

func FieldFilter

func FieldFilter(fieldName string, maskTypes ...masker.MType) Filter

FieldFilter returns a Field Filter.

func FieldPrefixFilter

func FieldPrefixFilter(prefix string, maskTypes ...masker.MType) Filter

FieldPrefixFilter returns a Field Prefix Filter.

func RegexFilter

func RegexFilter(regexPattern string, maskTypes ...masker.MType) Filter

RegexFilter returns a Regex Filter.

func TagFilter

func TagFilter(tags ...masker.MType) Filter

TagFilter creates a new filter with multiple tags input

func TagsFilter

func TagsFilter() Filter

TagsFilter returns a new filter instance with all available maskers

func ValueFilter

func ValueFilter(target string, maskTypes ...masker.MType) Filter

ValueFilter returns a Value Filter with custom masking type.

type Filters

type Filters []Filter

func (Filters) MaskString

func (fs Filters) MaskString(s string) string

MaskString .

func (Filters) ReplaceString

func (fs Filters) ReplaceString(s string) string

ReplaceString .

func (Filters) ShouldMask

func (fs Filters) ShouldMask(fieldName string, value interface{}, tag string) bool

ShouldMask .

type Masking

type Masking interface {
	Apply(v interface{}) interface{}
}

func New

func New(filters ...Filter) Masking

New creates a new Masking instance

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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