mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-11-12 20:23:46 +08:00
完成前后端框架搭建,完成聊天页面布局
This commit is contained in:
32
utils/utils.go
Normal file
32
utils/utils.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// RandString generate rand string with specified length
|
||||
func RandString(length int) string {
|
||||
str := "0123456789abcdefghijklmnopqrstuvwxyz"
|
||||
data := []byte(str)
|
||||
var result []byte
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
for i := 0; i < length; i++ {
|
||||
result = append(result, data[r.Intn(len(data))])
|
||||
}
|
||||
return string(result)
|
||||
}
|
||||
|
||||
func Long2IP(ipInt int64) string {
|
||||
b0 := strconv.FormatInt((ipInt>>24)&0xff, 10)
|
||||
b1 := strconv.FormatInt((ipInt>>16)&0xff, 10)
|
||||
b2 := strconv.FormatInt((ipInt>>8)&0xff, 10)
|
||||
b3 := strconv.FormatInt(ipInt&0xff, 10)
|
||||
return b0 + "." + b1 + "." + b2 + "." + b3
|
||||
}
|
||||
|
||||
func IsBlank(value string) bool {
|
||||
return len(strings.TrimSpace(value)) == 0
|
||||
}
|
||||
Reference in New Issue
Block a user