增加邮箱脱敏
This commit is contained in:
parent
235bb019cf
commit
3b56809ffe
@ -10,4 +10,6 @@ package data_mask
|
||||
const (
|
||||
// TypeDefault 默认实现
|
||||
TypeDefault = "DEFAULT_DATA_MASK"
|
||||
// TypeMail 邮箱数据脱敏
|
||||
TypeMail = "MAIL_DATA_MASK"
|
||||
)
|
||||
|
@ -13,7 +13,9 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
maskInstanceList := []IDataMask{}
|
||||
maskInstanceList := []IDataMask{
|
||||
&MailDataMask{}, // 邮箱脱敏
|
||||
}
|
||||
for _, item := range maskInstanceList {
|
||||
maskInstanceTable[item.Type()] = item
|
||||
}
|
||||
|
36
mail.go
Normal file
36
mail.go
Normal file
@ -0,0 +1,36 @@
|
||||
// Package data_mask ...
|
||||
//
|
||||
// Description : data_mask ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2023-05-24 14:40
|
||||
package data_mask
|
||||
|
||||
import "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 TypeMail
|
||||
}
|
23
mail_test.go
Normal file
23
mail_test.go
Normal file
@ -0,0 +1,23 @@
|
||||
// Package data_mask ...
|
||||
//
|
||||
// Description : data_mask ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2023-05-24 14:47
|
||||
package data_mask
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestMailDataMask_Mask ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 14:47 2023/5/24
|
||||
func TestMailDataMask_Mask(t *testing.T) {
|
||||
i := &MailDataMask{}
|
||||
fmt.Println(i.Mask("baichaqinghuan123@123.com"))
|
||||
}
|
Loading…
Reference in New Issue
Block a user