You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
626 B
Go
30 lines
626 B
Go
package utils
|
|
|
|
import (
|
|
"github.com/mileusna/useragent"
|
|
"strings"
|
|
)
|
|
|
|
func AddAsterisks(text string, prefixLen int, suffixLen int) string {
|
|
strLen := len(text)
|
|
padLen := strLen - prefixLen - suffixLen
|
|
if padLen <= 0 {
|
|
return text
|
|
}
|
|
return text[0:prefixLen] + strings.Repeat("*", padLen) + text[strLen-suffixLen:strLen]
|
|
}
|
|
|
|
func GetPlayerNameFromUserAgent(userAgentString string) string {
|
|
ua := useragent.Parse(userAgentString)
|
|
name := ua.OS
|
|
if ua.Mobile {
|
|
name += " 手机"
|
|
} else if ua.Tablet {
|
|
name += " 平板电脑"
|
|
} else if ua.Desktop {
|
|
name += " 电脑"
|
|
}
|
|
name += "上的 " + ua.Name
|
|
return name
|
|
}
|