masker

package
v0.0.0-...-f6ca644 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package masker Provide mask format of Taiwan usually used(Name, Address, Email, ID ...etc.),

Index

Constants

View Source
const (
	MPassword   mtype = "password"
	MName             = "name"
	MAddress          = "addr"
	MEmail            = "email"
	MMobile           = "mobile"
	MTelephone        = "tel"
	MID               = "id"
	MCreditCard       = "credit"
	MStruct           = "struct"
)

Maske Types of format string

Variables

This section is empty.

Functions

func Address

func Address(i string) string

Address keep first 6 letters, mask the rest

Example:

input: 台北市內湖區內湖路一段737巷1號1樓
output: 台北市內湖區******

func CreditCard

func CreditCard(i string) string

CreditCard mask 6 digits from the 7'th digit

Example:

input1: 1234567890123456 (VISA, JCB, MasterCard)(len = 16)
output1: 123456******3456
input2: 123456789012345 (American Express)(len = 15)
output2: 123456******345

func Email

func Email(i string) string

Email keep domain and the first 3 letters

Example:

input: ggw.chang@gmail.com
output: ggw****@gmail.com

func ID

func ID(i string) string

ID mask last 4 digits of ID number

Example:

input: A123456789
output: A12345****

func Mobile

func Mobile(i string) string

Mobile mask 3 digits from the 4'th digit

Example:

input: 0987654321
output: 0987***321

func Name

func Name(i string) string

Name mask the second letter and the third letter

Example:

input: ABCD
output: A**D

func Password

func Password(i string) string

Password always return "************"

func String

func String(t mtype, i string) string

String mask input string of the mask type

Example:

masker.String(masker.MName, "ggwhite")
masker.String(masker.MID, "A123456789")
masker.String(masker.MMobile, "0987987987")

func Struct

func Struct(s interface{}) (interface{}, error)

Struct must input a interface{}, add tag mask on struct fields, after Struct(), return a pointer interface{} of input type and it will be masked with the tag format type

Example:

type Foo struct {
    Name      string `mask:"name"`
    Email     string `mask:"email"`
    Password  string `mask:"password"`
    ID        string `mask:"id"`
    Address   string `mask:"addr"`
    Mobile    string `mask:"mobile"`
    Telephone string `mask:"tel"`
    Credit    string `mask:"credit"`
    Foo       *Foo   `mask:"struct"`
}

func main() {
    s := &Foo{
        Name: ...,
        Email: ...,
        Password: ...,
        Foo: &{
            Name: ...,
            Email: ...,
            Password: ...,
        }
    }

    t, err := masker.Struct(s)

    fmt.Println(t.(*Foo))
}

func Telephone

func Telephone(i string) string

Telephone remove "(", ")", " ", "-" chart, and mask last 4 digits of telephone number, format to "(??)????-????"

Example:

input: 0227993078
output: (02)2799-****

func UriPassword

func UriPassword(i string) string

Types

type Masker

type Masker struct{}

Masker is a instance to marshal masked string

func New

func New() *Masker

New create Masker

func (*Masker) Address

func (m *Masker) Address(i string) string

Address keep first 6 letters, mask the rest

Example:

input: 台北市內湖區內湖路一段737巷1號1樓
output: 台北市內湖區******

func (*Masker) CreditCard

func (m *Masker) CreditCard(i string) string

CreditCard mask 6 digits from the 7'th digit

Example:

input1: 1234567890123456 (VISA, JCB, MasterCard)(len = 16)
output1: 123456******3456
input2: 123456789012345` (American Express)(len = 15)
output2: 123456******345`

func (*Masker) Email

func (m *Masker) Email(i string) string

Email keep domain and the first 3 letters

Example:

input: ggw.chang@gmail.com
output: ggw****@gmail.com

func (*Masker) ID

func (m *Masker) ID(i string) string

ID mask last 4 digits of ID number

Example:

input: A123456789
output: A12345****

func (*Masker) Mobile

func (m *Masker) Mobile(i string) string

Mobile mask 3 digits from the 4'th digit

Example:

input: 0987654321
output: 0987***321

func (*Masker) Name

func (m *Masker) Name(i string) string

Name mask the second letter and the third letter

Example:

input: ABCD
output: A**D

func (*Masker) Password

func (m *Masker) Password(i string) string

Password always return "************"

func (*Masker) String

func (m *Masker) String(t mtype, i string) string

String mask input string of the mask type

Example:

masker.String(masker.MName, "ggwhite")
masker.String(masker.MID, "A123456789")
masker.String(masker.MMobile, "0987987987")

func (*Masker) Struct

func (m *Masker) Struct(s interface{}) (interface{}, error)

Struct must input a interface{}, add tag mask on struct fields, after Struct(), return a pointer interface{} of input type and it will be masked with the tag format type

Example:

type Foo struct {
    Name      string `mask:"name"`
    Email     string `mask:"email"`
    Password  string `mask:"password"`
    ID        string `mask:"id"`
    Address   string `mask:"addr"`
    Mobile    string `mask:"mobile"`
    Telephone string `mask:"tel"`
    Credit    string `mask:"credit"`
    Foo       *Foo   `mask:"struct"`
}

func main() {
    s := &Foo{
        Name: ...,
        Email: ...,
        Password: ...,
        Foo: &{
            Name: ...,
            Email: ...,
            Password: ...,
        }
    }

    m := masker.New()

    t, err := m.Struct(s)

    fmt.Println(t.(*Foo))
}

func (*Masker) Telephone

func (m *Masker) Telephone(i string) string

Telephone remove "(", ")", " ", "-" chart, and mask last 4 digits of telephone number, format to "(??)????-????"

Example:

input: 0227993078
output: (02)2799-****

Jump to

Keyboard shortcuts

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