|
@@ -33,7 +33,7 @@ var ErrNoRow = gorm.ErrRecordNotFound
|
|
|
)*/
|
|
|
|
|
|
// 发放token
|
|
|
-func GenToken(account string)(accessToken string, err error) {
|
|
|
+func GenToken(account string) (accessToken string, err error) {
|
|
|
/*token := jwt.New(jwt.SigningMethodHS256)
|
|
|
token.Claims = &jwt.StandardClaims{
|
|
|
NotBefore: int64(time.Now().Unix()),
|
|
@@ -48,7 +48,7 @@ func GenToken(account string)(accessToken string, err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//随机数种子
|
|
|
+// 随机数种子
|
|
|
var rnd = rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
|
|
|
|
// GetRandString 获取随机字符串
|
|
@@ -406,8 +406,8 @@ func TrimHtml(src string) string {
|
|
|
return strings.TrimSpace(src)
|
|
|
}
|
|
|
|
|
|
-//1556164246 -> 2019-04-25 03:50:46 +0000
|
|
|
-//timestamp
|
|
|
+// 1556164246 -> 2019-04-25 03:50:46 +0000
|
|
|
+// timestamp
|
|
|
// TimeToTimestamp
|
|
|
func TimeToTimestamp() {
|
|
|
fmt.Println(time.Unix(1556164246, 0).Format(FormatDateTime))
|
|
@@ -421,6 +421,7 @@ func TimeTransferString(format string, t time.Time) string {
|
|
|
}
|
|
|
return str
|
|
|
}
|
|
|
+
|
|
|
// ToUnicode
|
|
|
func ToUnicode(text string) string {
|
|
|
textQuoted := strconv.QuoteToASCII(text)
|
|
@@ -466,7 +467,7 @@ func GetWilsonScore(p, n float64) float64 {
|
|
|
return toFixed(((p+1.9208)/(p+n)-1.96*math.Sqrt(p*n/(p+n)+0.9604)/(p+n))/(1+3.8416/(p+n)), 2)
|
|
|
}
|
|
|
|
|
|
-//将中文数字转化成数字,比如 第三百四十五章,返回第345章 不支持一亿及以上
|
|
|
+// 将中文数字转化成数字,比如 第三百四十五章,返回第345章 不支持一亿及以上
|
|
|
func ChangeWordsToNum(str string) (numStr string) {
|
|
|
words := ([]rune)(str)
|
|
|
num := 0
|
|
@@ -642,14 +643,14 @@ func GetMonthStartAndEnd(myYear string, myMonth string) (startDate, endDate stri
|
|
|
return t1, t2
|
|
|
}
|
|
|
|
|
|
-//TrimStr 移除字符串中的空格
|
|
|
+// TrimStr 移除字符串中的空格
|
|
|
func TrimStr(str string) (str2 string) {
|
|
|
return strings.Replace(str, " ", "", -1)
|
|
|
}
|
|
|
|
|
|
// StrTimeToTime 字符串转换为time
|
|
|
func StrTimeToTime(strTime string) time.Time {
|
|
|
- timeLayout := FormatDateTime //转化所需模板
|
|
|
+ timeLayout := FormatDateTime //转化所需模板
|
|
|
loc, _ := time.LoadLocation("Local") //重要:获取时区
|
|
|
resultTime, _ := time.ParseInLocation(timeLayout, strTime, loc)
|
|
|
return resultTime
|
|
@@ -992,8 +993,8 @@ func InArray(needle interface{}, hyStack interface{}) bool {
|
|
|
|
|
|
// bit转MB 保留小数
|
|
|
func Bit2MB(bitSize int64, prec int) (size float64) {
|
|
|
- mb := float64(bitSize)/float64(1024*1024)
|
|
|
- size, _ = strconv.ParseFloat(strconv.FormatFloat(mb,'f',prec,64), 64)
|
|
|
+ mb := float64(bitSize) / float64(1024*1024)
|
|
|
+ size, _ = strconv.ParseFloat(strconv.FormatFloat(mb, 'f', prec, 64), 64)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -1008,7 +1009,7 @@ func SubStr(str string, subLen int) string {
|
|
|
return str
|
|
|
}
|
|
|
|
|
|
-func GetInterfaceAddrs() (ip string) {
|
|
|
+func GetInterfaceAddrs() (ip string) {
|
|
|
addrs, err := net.InterfaceAddrs()
|
|
|
if err != nil {
|
|
|
fmt.Println(err)
|
|
@@ -1025,4 +1026,26 @@ func GetInterfaceAddrs() (ip string) {
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
-}
|
|
|
+}
|
|
|
+
|
|
|
+// InArrayByInt php中的in_array(判断Int类型的切片中是否存在该int值)
|
|
|
+func InArrayByInt(idIntList []int, searchId int) (has bool) {
|
|
|
+ for _, id := range idIntList {
|
|
|
+ if id == searchId {
|
|
|
+ has = true
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// InArrayByStr php中的in_array(判断String类型的切片中是否存在该string值)
|
|
|
+func InArrayByStr(idStrList []string, searchId string) (has bool) {
|
|
|
+ for _, id := range idStrList {
|
|
|
+ if id == searchId {
|
|
|
+ has = true
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|