// 各种字符串加星
匹配 手机号,邮箱,中文,身份证等等
// 各种字符串加星
func HideStar(str string) (result string) {
if str == "" {
return "***"
}
if strings.Contains(str,"@") {
res := strings.Split(str,"@")
if len(res[0]) < 3 {
resString := "***"
result = resString + "@" + res[1]
} else {
res2 := Substr2(str,0,3)
resString := res2 + "***"
result = resString + "@" + res[1]
}
return result
} else {
reg := `^1[0-9]\d{9}$`
rgx := regexp.MustCompile(reg)
mobileMatch := rgx.MatchString(str)
if mobileMatch {
result = Substr2(str,0,3) + "****" + Substr2(str,7,11)
} else {
nameRune := []rune(str)
lens := len(nameRune)
if lens <= 1 {
result = "***"
} else if lens == 2 {
result = string(nameRune[:1]) + "*"
} else if lens == 3 {
result = string(nameRune[:1]) + "*" + string(nameRune[2:3])
} else if lens == 4 {
result = string(nameRune[:1]) + "**" + string(nameRune[lens - 1 : lens])
} else if lens > 4 {
result = string(nameRune[:2]) + "***" + string(nameRune[lens - 2 : lens])
}
}
return
}
}
func Substr2(str string, start int, end int) string {
rs := []rune(str)
return string(rs[start:end])
}
本站(PHP --> Golang)已重构,代码开源
当你能力不能满足你的野心的时候,你就该沉下心来学习
喜欢没事就coding
然后想系统性的练练之前知道的东西..
然后顺便了解下前端..
于是写了一个小作品!虽然我并不知道有什么卵用….
前台: 基于vue的elementUI组件开发的 前台地址
后台: 基于vue的iview组件开发的 后台地址 (目前还在调试阶段)
后端数据: 基于php的Laravel框架提供的数据!
移动端: 微信小程序(因为个人的,发布不了论坛,所以目前还未上线!)
待开发:
全文检索: 打算用Go的全文检索
消息通知: 打算用微信公众号进行同步!
那么,代码呢?完全开源!随便玩..就是各个项目分离的比较散..而且暂时没有时间写完整教程…等功能差不多了,我再补补教程!
前台地址: https://github.com/g9zz/g9zz-ele-index
后台地址: https://github.com/g9zz/yeluo-iview-backend
数据地址: https://github.com/g9zz/g9zz-bbs
小程序地址: https://github.com/g9zz/g9zz-xcx
本站(PHP --> Golang)已重构,代码开源
当你能力不能满足你的野心的时候,你就该沉下心来学习