/*
* @,@Author: ,: lxcos
* @,@Date: ,: 2020-10-31 17:36:39
*/
package main
import (
"github.com/sirupsen/logrus"
)
func main() {
customFormatter := new(logrus.TextFormatter)
customFormatter.TimestampFormat = "2006-01-02 15:04:05"
customFormatter.FullTimestamp = true
logrus.SetFormatter(customFormatter)
logrus.Info("Hello Walrus after FullTimestamp=true")
}
關(guān)于字符串拼接效率:
單詞調(diào)用字符串拼接性能 + > strings.Join > bytes.Buffer > fmt.Sprintf
大量數(shù)據(jù)拼接推薦bytes.buffer{}圣勒,bytes.buffer的性能是非常高的懂拾。
隨機字符串生成器:
func RandomString(n int, allowedChars ...[]rune) string {
var letters []rune
if len(allowedChars) == 0 {
letters = defaultLetters
} else {
letters = allowedChars[0]
}
b := make([]rune, n)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
return string(b)
}
-------------------------------------------------------------------------------------
func GetNoceStr() string {
char := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789=_"
rand.NewSource(time.Now().UnixNano()) // 產(chǎn)生隨機種子
var s bytes.Buffer
for i := 0; i < 32; i ++ {
s.WriteByte(char[rand.Int63() % int64(len(char))])
}
return s.String()
}