rename
This commit is contained in:
39
strategy/mail.go
Normal file
39
strategy/mail.go
Normal file
@ -0,0 +1,39 @@
|
||||
// Package data_mask ...
|
||||
//
|
||||
// Description : data_mask ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2023-05-24 14:40
|
||||
package strategy
|
||||
|
||||
import (
|
||||
"git.zhangdeman.cn/zhangdeman/data_mask/define"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// MailDataMask ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 14:40 2023/5/24
|
||||
type MailDataMask struct {
|
||||
}
|
||||
|
||||
func (m MailDataMask) Mask(input string) string {
|
||||
input = strings.TrimSpace(input)
|
||||
if !strings.Contains(input, "@") || strings.HasPrefix(input, "@") {
|
||||
// 不是邮箱
|
||||
return input
|
||||
}
|
||||
arr := strings.Split(input, "@")
|
||||
if len(arr) != 2 {
|
||||
return input
|
||||
}
|
||||
|
||||
return string(arr[0][0]) + "********" + string(arr[0][len(arr[0])-1]) + "@" + arr[1]
|
||||
}
|
||||
|
||||
func (m MailDataMask) Type() string {
|
||||
return define.TypeMail
|
||||
}
|
24
strategy/mail_test.go
Normal file
24
strategy/mail_test.go
Normal file
@ -0,0 +1,24 @@
|
||||
// Package data_mask ...
|
||||
//
|
||||
// Description : data_mask ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2023-05-24 14:47
|
||||
package strategy
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestMailDataMask_Mask ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 14:47 2023/5/24
|
||||
func TestMailDataMask_Mask(t *testing.T) {
|
||||
i := &MailDataMask{}
|
||||
input := "baichaqinghuan123@123.com"
|
||||
fmt.Println(input, "--------------->", i.Mask(input))
|
||||
}
|
28
strategy/password.go
Normal file
28
strategy/password.go
Normal file
@ -0,0 +1,28 @@
|
||||
// Package strategy ...
|
||||
//
|
||||
// Description : data_mask ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2023-05-24 15:02
|
||||
package strategy
|
||||
|
||||
import (
|
||||
"git.zhangdeman.cn/zhangdeman/data_mask/define"
|
||||
)
|
||||
|
||||
// PasswordDataMask 密码数据脱敏
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 15:04 2023/5/24
|
||||
type PasswordDataMask struct {
|
||||
}
|
||||
|
||||
func (p PasswordDataMask) Mask(input string) string {
|
||||
return "********"
|
||||
}
|
||||
|
||||
func (p PasswordDataMask) Type() string {
|
||||
return define.TypePassword
|
||||
}
|
41
strategy/phone.go
Normal file
41
strategy/phone.go
Normal file
@ -0,0 +1,41 @@
|
||||
// Package strategy ...
|
||||
//
|
||||
// Description : data_mask ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2023-05-24 14:52
|
||||
package strategy
|
||||
|
||||
import (
|
||||
"git.zhangdeman.cn/zhangdeman/data_mask/define"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
// PhoneDataMask ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 14:57 2023/5/24
|
||||
type PhoneDataMask struct {
|
||||
}
|
||||
|
||||
func (p PhoneDataMask) Mask(input string) string {
|
||||
// 匹配规则
|
||||
// ^1第一位为一
|
||||
// [345789]{1} 后接一位345789 的数字
|
||||
// \\d \d的转义 表示数字 {9} 接9位
|
||||
// $ 结束符
|
||||
regRuler := "^1[345789]{1}\\d{9}$"
|
||||
// 正则调用规则
|
||||
reg := regexp.MustCompile(regRuler)
|
||||
// 返回 MatchString 是否匹配
|
||||
if !reg.MatchString(input) {
|
||||
return input
|
||||
}
|
||||
return string(input[0:3]) + "******" + string(input[9:11])
|
||||
}
|
||||
|
||||
func (p PhoneDataMask) Type() string {
|
||||
return define.TypePhone
|
||||
}
|
19
strategy/phone_test.go
Normal file
19
strategy/phone_test.go
Normal file
@ -0,0 +1,19 @@
|
||||
// Package data_mask ...
|
||||
//
|
||||
// Description : data_mask ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2023-05-24 14:57
|
||||
package strategy
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPhoneDataMask_Mask(t *testing.T) {
|
||||
i := &PhoneDataMask{}
|
||||
input := "18940952935"
|
||||
fmt.Println(input, "------------>", i.Mask(input))
|
||||
}
|
Reference in New Issue
Block a user