This commit is contained in:
ryan
2026-06-08 14:34:09 +08:00
parent db68a130ce
commit 72c74803be
17 changed files with 596 additions and 58 deletions
+16
View File
@@ -16,6 +16,8 @@ limitations under the License.
package util
import "strings"
// DerefString 安全地解引用字符串指针,nil 返回空字符串
func DerefString(s *string) string {
if s == nil {
@@ -23,3 +25,17 @@ func DerefString(s *string) string {
}
return *s
}
// MaskEmail 安全脱敏用户的邮箱地址(例如 us***@example.com)
func MaskEmail(email string) string {
parts := strings.Split(email, "@")
if len(parts) != 2 {
return email
}
local := parts[0]
domain := parts[1]
if len(local) <= 2 {
return "**@" + domain
}
return local[:2] + "***" + local[len(local)-1:] + "@" + domain
}