utils.go 622 字节
Newer Older
Y
Your Name 已提交
1
package gokunode
E
eoLinker API Management 已提交
2 3 4 5 6 7 8

import (
	"math/rand"
	"strings"
	"time"
)

Y
Your Name 已提交
9
// GetRandomString 生成随机字符串
E
eoLinker API Management 已提交
10 11 12 13 14 15 16 17 18 19 20
func GetRandomString(num int) string {
	str := "123456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ"
	bytes := []byte(str)
	result := []byte{}
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	for i := 0; i < num; i++ {
		result = append(result, bytes[r.Intn(len(bytes))])
	}
	return string(result)
}

Y
Your Name 已提交
21
//Intercept 过滤子字符串
E
eoLinker API Management 已提交
22 23 24 25 26 27 28 29 30 31
func Intercept(str, substr string) string {
	result := strings.Index(str, substr)
	var rs string
	if result != -1 {
		rs = str[:result]
	} else {
		rs = str
	}
	return rs
}