Initial cloud-services repo - gateway service + pkg modules
This commit is contained in:
30
pkg/logger/mask.go
Normal file
30
pkg/logger/mask.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// MaskEmail removes all identifying chars except first from email username
|
||||
func MaskEmail(s string) string {
|
||||
tmp := strings.Split(s, "@")
|
||||
addr := tmp[0]
|
||||
domain := tmp[1]
|
||||
if len(addr) <= 0 || len(domain) <= 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
addr = addr[:1] + strings.Repeat("*", len(addr)-1)
|
||||
return addr + "@" + domain
|
||||
}
|
||||
|
||||
// MaskPassword replaces all characters
|
||||
func MaskPassword(s string) string {
|
||||
return strings.Repeat("*", len(s))
|
||||
}
|
||||
|
||||
// MaskPhoneNumber replaces all nums except first from number string
|
||||
func MaskPhoneNumber(s string) string {
|
||||
m := regexp.MustCompile(`\B\d`)
|
||||
return m.ReplaceAllString(s, "*")
|
||||
}
|
||||
Reference in New Issue
Block a user