masker

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2024 License: MIT Imports: 1 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Mask

func Mask[T any](target T) (ret T, err error)

Types

type MaskAnyFunc

type MaskAnyFunc func(arg string, value any) (any, error)

type MaskFloat64Func

type MaskFloat64Func func(arg string, value float64) (float64, error)

type MaskIntFunc

type MaskIntFunc func(arg string, value int) (int, error)

type MaskStringFunc

type MaskStringFunc func(arg string, value string) (string, error)

type MaskUintFunc

type MaskUintFunc func(arg string, value uint) (uint, error)

type Masker

type Masker struct {
	// contains filtered or unexported fields
}
var Default *Masker

func (*Masker) Cache

func (m *Masker) Cache(enable bool)

Cache can be toggled to cache the type information of the struct. default true

func (*Masker) Float64

func (m *Masker) Float64(tag string, value float64) (float64, error)

Float64 masks the given argument float64

func (*Masker) Int

func (m *Masker) Int(tag string, value int) (int, error)

Int masks the given argument int

func (*Masker) Mask

func (m *Masker) Mask(target any) (ret any, err error)

Mask returns an object with the mask applied to any given object. The function's argument can accept any type, including pointer, map, and slice types, in addition to struct.

func (*Masker) MaskChar

func (m *Masker) MaskChar() string

MaskChar returns the current character used for masking.

func (*Masker) MaskFilledString

func (m *Masker) MaskFilledString(arg, value string) (string, error)

MaskFilledString masks the string length of the value with the same length. If you pass a number like "2" to arg, it masks with the length of the number.(**)

func (*Masker) MaskFixedString

func (m *Masker) MaskFixedString(arg, value string) (string, error)

MaskFixedString masks with a fixed length (8 characters).

func (*Masker) MaskHashString

func (m *Masker) MaskHashString(arg, value string) (string, error)

MaskHashString masks and hashes (sha1) a string.

func (*Masker) MaskRandomFloat64

func (m *Masker) MaskRandomFloat64(arg string, value float64) (float64, error)

MaskRandomFloat64 converts a float64 to a random number. For example, if you pass "100.3" to arg, it sets a random number in the range of 0.000 to 99.999.

func (*Masker) MaskRandomInt

func (m *Masker) MaskRandomInt(arg string, value int) (int, error)

MaskRandomInt converts an integer (int) into a random number. For example, if you pass "100" as the arg, it sets a random number in the range of 0-99.

func (*Masker) MaskZero

func (m *Masker) MaskZero(arg string, value any) (any, error)

MaskZero converts the value to its type's zero value.

func (*Masker) RegisterMaskAnyFunc

func (m *Masker) RegisterMaskAnyFunc(maskType string, maskFunc MaskAnyFunc)

RegisterMaskAnyFunc registers a masking function that can be applied to any type. The function will be applied when the string set in the first argument is assigned as a tag to a field in the structure.

func (*Masker) RegisterMaskField

func (m *Masker) RegisterMaskField(fieldName, maskType string)

RegisterMaskField allows you to register a mask tag to be applied to the value of a struct field or map key that matches the fieldName. If a mask tag is set on the struct field, it will take precedence.

func (*Masker) RegisterMaskFloat64Func

func (m *Masker) RegisterMaskFloat64Func(maskType string, maskFunc MaskFloat64Func)

RegisterMaskFloat64Func registers a masking function for float64 values. The function will be applied when the string set in the first argument is assigned as a tag to a field in the structure.

func (*Masker) RegisterMaskIntFunc

func (m *Masker) RegisterMaskIntFunc(maskType string, maskFunc MaskIntFunc)

RegisterMaskIntFunc registers a masking function for int values. The function will be applied when the string set in the first argument is assigned as a tag to a field in the structure.

func (*Masker) RegisterMaskStringFunc

func (m *Masker) RegisterMaskStringFunc(maskType string, maskFunc MaskStringFunc)

RegisterMaskStringFunc registers a masking function for string values. The function will be applied when the string set in the first argument is assigned as a tag to a field in the structure.

func (*Masker) RegisterMaskUintFunc

func (m *Masker) RegisterMaskUintFunc(maskType string, maskFunc MaskUintFunc)

RegisterMaskUintFunc registers a masking function for uint values. The function will be applied when the uint slice set in the first argument is assigned as a tag to a field in the structure.

func (*Masker) SetMaskChar

func (m *Masker) SetMaskChar(s string)

SetMaskChar changes the character used for masking

func (*Masker) SetTagName

func (m *Masker) SetTagName(s string)

SetTagName allows you to change the tag name from "mask" to something else.

func (*Masker) String

func (m *Masker) String(tag, value string) (string, error)

String masks the given argument string

func (*Masker) Uint

func (m *Masker) Uint(tag string, value uint) (uint, error)

Uint masks the given argument uint

Jump to

Keyboard shortcuts

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