first commit
This commit is contained in:
17
handle/id_card.go
Normal file
17
handle/id_card.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package handle
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// IdCard
|
||||
// @description: 脱敏规则: 身份证号码
|
||||
// @param src string: 待处理字符串
|
||||
// @param placeholder string: 占位符
|
||||
// @return dst string: 脱敏后的数据
|
||||
func IdCard(src, placeholder string) (dst string) {
|
||||
// 保留前六位后两位
|
||||
dst = src[:6] + strings.Repeat(placeholder, utf8.RuneCountInString(src)-7) + src[len(src)-2:]
|
||||
return
|
||||
}
|
21
handle/phone.go
Normal file
21
handle/phone.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package handle
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// Phone
|
||||
// @description: 脱敏规则: 手机号
|
||||
// @param src string: 待处理字符串
|
||||
// @param placeholder string: 占位符
|
||||
// @return dst string: 脱敏后的数据
|
||||
func Phone(src, placeholder string) (dst string) {
|
||||
// 不足7位,直接返回
|
||||
if utf8.RuneCountInString(src) <= 7 {
|
||||
return src
|
||||
}
|
||||
// 取前三位和后四位
|
||||
dst = src[:3] + strings.Repeat(placeholder, utf8.RuneCountInString(src)-7) + src[len(src)-4:]
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user