sensitive/handle/phone.go
2022-08-26 10:35:14 +08:00

22 lines
498 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}