Documentation ¶
Overview ¶
Package masker Provide mask format of Taiwan usually used(Name, Address, Email, ID ...etc.),
Index ¶
- Constants
- func Address(i string) string
- func CreditCard(i string) string
- func Email(i string) string
- func ID(i string) string
- func Mobile(i string) string
- func Name(i string) string
- func Password(i string) string
- func SetMask(mask string)
- func String(t mtype, i string) string
- func Struct(s interface{}) (interface{}, error)
- func Telephone(i string) string
- type Masker
- func (m *Masker) Address(i string) string
- func (m *Masker) CreditCard(i string) string
- func (m *Masker) Email(i string) string
- func (m *Masker) ID(i string) string
- func (m *Masker) Mobile(i string) string
- func (m *Masker) Name(i string) string
- func (m *Masker) Password(i string) string
- func (m *Masker) String(t mtype, i string) string
- func (m *Masker) Struct(s interface{}) (interface{}, error)
- func (m *Masker) Telephone(i string) string
- func (m *Masker) URL(i string) string
Constants ¶
const ( MPassword mtype = "password" MName mtype = "name" MAddress mtype = "addr" MEmail mtype = "email" MMobile mtype = "mobile" MTelephone mtype = "tel" MID mtype = "id" MCreditCard mtype = "credit" MStruct mtype = "struct" MURL mtype = "url" )
Maske Types of format string
Variables ¶
This section is empty.
Functions ¶
func Address ¶
Address keep first 6 letters, mask the rest
Example:
input: 台北市內湖區內湖路一段737巷1號1樓 output: 台北市內湖區******
func CreditCard ¶
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 ¶
Email keep domain and the first 3 letters
Example:
input: ggw.chang@gmail.com output: ggw****@gmail.com
func Mobile ¶
Mobile mask 3 digits from the 4'th digit
Example:
input: 0987654321 output: 0987***321
func 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)) }
Types ¶
type Masker ¶
type Masker struct {
// contains filtered or unexported fields
}
Masker is a instance to marshal masked string
func (*Masker) Address ¶
Address keep first 6 letters, mask the rest
Example:
input: 台北市內湖區內湖路一段737巷1號1樓 output: 台北市內湖區******
func (*Masker) CreditCard ¶
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 ¶
Email keep domain and the first 3 letters
Example:
input: ggw.chang@gmail.com output: ggw****@gmail.com
func (*Masker) ID ¶
ID mask last 4 digits of ID number
Example:
input: A123456789 output: A12345****
func (*Masker) Mobile ¶
Mobile mask 3 digits from the 4'th digit
Example:
input: 0987654321 output: 0987***321
func (*Masker) Name ¶
Name mask the second letter and the third letter
Example:
input: ABCD output: A**D
func (*Masker) 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 ¶
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)) }