|
|
@@ -10,6 +10,7 @@ import (
|
|
|
"net/url"
|
|
|
"regexp"
|
|
|
"strings"
|
|
|
+ "fmt"
|
|
|
)
|
|
|
|
|
|
const (
|
|
|
@@ -17,8 +18,12 @@ const (
|
|
|
)
|
|
|
|
|
|
func NewUUID() string {
|
|
|
- //return uuid.NewV4().String()
|
|
|
- return uuid.New()
|
|
|
+ id, err := GetGid("2")
|
|
|
+ if err != nil {
|
|
|
+ return uuid.New()
|
|
|
+ } else {
|
|
|
+ return fmt.Sprint(id)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
func GenerateToken(plain string) string {
|
|
|
@@ -53,10 +58,10 @@ func FormatForBrowse(agent, val string) string {
|
|
|
return val
|
|
|
}
|
|
|
|
|
|
-func GetHostname(ctx *gin.Context)string{
|
|
|
+func GetHostname(ctx *gin.Context) string {
|
|
|
host := ctx.Request.Host
|
|
|
i := strings.Index(host, ":")
|
|
|
- if i > 0{
|
|
|
+ if i > 0 {
|
|
|
host = host[:i]
|
|
|
}
|
|
|
|
|
|
@@ -67,24 +72,24 @@ func GetHostname(ctx *gin.Context)string{
|
|
|
* @brief: 把域名分成列表,最小包括部分顶级域名,例如:www.baidu.com 返回[www.baidu.com, baidu.com]
|
|
|
× @param1 hostname: 请求名称
|
|
|
*/
|
|
|
-func GetHostnames(ctx *gin.Context)[]string{
|
|
|
+func GetHostnames(ctx *gin.Context) []string {
|
|
|
hostname := GetHostname(ctx)
|
|
|
patternstr := `(2(5[0-5]{1}|[0-4]\d{1})|[0-1]?\d{1,2})(\.(2(5[0-5]{1}|[0-4]\d{1})|[0-1]?\d{1,2})){3}`
|
|
|
reg := regexp.MustCompile(patternstr)
|
|
|
if res := reg.FindAllString(hostname, -1); res == nil {
|
|
|
arr := []string{}
|
|
|
parts := strings.Split(hostname, ".")
|
|
|
- if len(parts) <= 2{
|
|
|
+ if len(parts) <= 2 {
|
|
|
arr = append(arr, hostname)
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
arr = append(arr, hostname)
|
|
|
- for i := 0; i < len(parts) - 2; i++ {
|
|
|
+ for i := 0; i < len(parts)-2; i++ {
|
|
|
arr = append(arr, strings.Join(parts[i+1:], "."))
|
|
|
}
|
|
|
}
|
|
|
- return arr
|
|
|
+ return arr
|
|
|
} else {
|
|
|
// 直接返回ip
|
|
|
return []string{hostname}
|
|
|
}
|
|
|
-}
|
|
|
+}
|