mask

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2023 License: MIT Imports: 6 Imported by: 2

README

go-mask

mask and cut value for struct.

priority:

  • NotMaskReg
  • MaskReg
  • CustomMask
  • MaxLength
m := mask.New(
    mask.RegExpOption(regexp.MustCompile("password")),
    mask.MaxLengthOption(3),
    mask.CustomMaskOption(regexp.MustCompile("desc"), func(key, value string) string {
        max := 10
        if len(value) <= max {
            return value
        }
        return value[0:max] + "..."
    }),
)
result := m.Struct(struct {
    Name string `json:"name"`
    Password string `json:"password"`
    Desc string `json:"desc"`
}{
    "test",
    "password",
    "desc",
})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CustomMask added in v0.2.0

type CustomMask struct {
	Reg     *regexp.Regexp
	Handler MaskHandler
}

type Mask

type Mask struct {
	NotMaskReg  *regexp.Regexp
	Reg         *regexp.Regexp
	MaxLength   int
	CustomMasks []*CustomMask
}

func New

func New(opts ...MaskOption) *Mask

func (*Mask) Struct

func (m *Mask) Struct(data interface{}) (map[string]interface{}, error)

Struct converts struct to map[string]interface{} with mask

func (*Mask) URLValues added in v0.0.2

func (m *Mask) URLValues(data url.Values) map[string]interface{}

URLValues converts url values to map[string]interface{} with mask

type MaskHandler added in v0.2.0

type MaskHandler func(key, value string) string

type MaskOption

type MaskOption func(*Mask)

func CustomMaskOption added in v0.2.0

func CustomMaskOption(reg *regexp.Regexp, handler MaskHandler) MaskOption

CustomMaskOption add custom mask regexp option

func MaxLengthOption

func MaxLengthOption(maxLength int) MaskOption

Set max string length option for mask, if the length of rune is gt max, it will convert to %s ... (%d more runes) 0 means no limit.

func NotMaskRegExpOption added in v0.1.0

func NotMaskRegExpOption(reg *regexp.Regexp) MaskOption

NotMaskRegExpOption sets not mask regexp option

func RegExpOption

func RegExpOption(reg *regexp.Regexp) MaskOption

RegExpOption sets regexp option

Jump to

Keyboard shortcuts

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