data_mask/strategy/name.go

45 lines
850 B
Go
Raw Normal View History

2024-09-23 16:30:41 +08:00
// 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
}