data_mask/execute.go

39 lines
879 B
Go
Raw Normal View History

2023-05-23 14:32:26 +08:00
// Package data_mask ...
//
// Description : data_mask ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2023-05-23 14:25
package data_mask
2024-04-07 21:35:55 +08:00
import "git.zhangdeman.cn/zhangdeman/data_mask/strategy"
2023-05-23 14:32:26 +08:00
var (
maskInstanceTable = make(map[string]IDataMask)
defaultDataMask = &DefaultDataMask{}
)
func init() {
2023-05-24 14:51:45 +08:00
maskInstanceList := []IDataMask{
2024-04-07 21:35:55 +08:00
&strategy.MailDataMask{}, // 邮箱脱敏
&strategy.PhoneDataMask{}, // 手机号脱敏
2023-05-24 14:51:45 +08:00
}
2023-05-23 14:32:26 +08:00
for _, item := range maskInstanceList {
maskInstanceTable[item.Type()] = item
}
}
// Execute 执行数据脱敏
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 14:31 2023/5/23
func Execute(data string, maskType string) string {
dataMaskInstance, exist := maskInstanceTable[maskType]
if !exist || nil == dataMaskInstance {
dataMaskInstance = defaultDataMask
}
return dataMaskInstance.Mask(data)
}