姓名脱敏
This commit is contained in:
parent
582283faf9
commit
7f49019653
@ -8,14 +8,11 @@
|
||||
package define
|
||||
|
||||
const (
|
||||
// TypeDefault 默认实现
|
||||
TypeDefault = "DEFAULT_DATA_MASK"
|
||||
// TypeMail 邮箱数据脱敏
|
||||
TypeMail = "MAIL_DATA_MASK"
|
||||
// TypePhone 手机号脱敏
|
||||
TypePhone = "PHONE_DATA_MASK"
|
||||
// TypePassword 密码数据脱敏
|
||||
TypePassword = "PASSWORD_DATA_MASK"
|
||||
TypeDefault = "DEFAULT_DATA_MASK" // 默认实现
|
||||
TypeMail = "MAIL_DATA_MASK" // 邮箱数据脱敏
|
||||
TypePhone = "PHONE_DATA_MASK" // 手机号脱敏
|
||||
TypePassword = "PASSWORD_DATA_MASK" // 密码数据脱敏
|
||||
TypeName = "NAME_DATA_MASK" // 姓名数据脱敏
|
||||
)
|
||||
|
||||
// TypeDesc 脱敏类型描述
|
||||
@ -34,5 +31,6 @@ var (
|
||||
{TypeMail, "邮箱数据脱敏"},
|
||||
{TypePhone, "手机号数据脱敏"},
|
||||
{TypePassword, "密码数据脱敏"},
|
||||
{TypeName, "姓名数据脱敏"},
|
||||
}
|
||||
)
|
||||
|
@ -19,8 +19,11 @@ var (
|
||||
|
||||
func init() {
|
||||
maskInstanceList := []IDataMask{
|
||||
&strategy.MailDataMask{}, // 邮箱脱敏
|
||||
&strategy.PhoneDataMask{}, // 手机号脱敏
|
||||
&strategy.MailDataMask{}, // 邮箱脱敏
|
||||
&strategy.PhoneDataMask{}, // 手机号脱敏
|
||||
&strategy.PasswordDataMask{}, // 密码脱敏
|
||||
&DefaultDataMask{}, // 默认脱敏
|
||||
&strategy.NameDataMask{}, // 姓名脱敏
|
||||
}
|
||||
for _, item := range maskInstanceList {
|
||||
maskInstanceTable[item.Type()] = item
|
||||
|
44
strategy/name.go
Normal file
44
strategy/name.go
Normal file
@ -0,0 +1,44 @@
|
||||
// Package strategy ...
|
||||
//
|
||||
// Description : strategy ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2024-09-23 16:25
|
||||
package strategy
|
||||
|
||||
import (
|
||||
"git.zhangdeman.cn/zhangdeman/data_mask/define"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// NameDataMask 姓名脱敏
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 16:30 2024/9/23
|
||||
type NameDataMask struct {
|
||||
}
|
||||
|
||||
func (n *NameDataMask) Mask(input string) string {
|
||||
if len(input) == 0 {
|
||||
return ""
|
||||
}
|
||||
nameArr := strings.Split(input, "")
|
||||
if len(nameArr) == 2 {
|
||||
return nameArr[0] + "*"
|
||||
}
|
||||
return nameArr[0] + n.getMaskString(len(nameArr)) + nameArr[len(nameArr)-1]
|
||||
}
|
||||
|
||||
func (n *NameDataMask) Type() string {
|
||||
return define.TypeName
|
||||
}
|
||||
|
||||
func (n *NameDataMask) getMaskString(nameLength int) string {
|
||||
maskStr := ""
|
||||
for i := 0; i < nameLength-2; i++ {
|
||||
maskStr = maskStr + "*"
|
||||
}
|
||||
return maskStr
|
||||
}
|
Loading…
Reference in New Issue
Block a user