From b13d9eaf2721f68d163225b8efb318c0870a78c2 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 14 Jul 2020 13:50:52 +0800 Subject: [PATCH] chore: add some funcs --- strutil/strutil.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/strutil/strutil.go b/strutil/strutil.go index 2fdddcc..62ad2d3 100644 --- a/strutil/strutil.go +++ b/strutil/strutil.go @@ -5,13 +5,15 @@ import ( "crypto/md5" "encoding/hex" "fmt" - "github.com/google/uuid" - "github.com/sssvip/goutil/logutil" "io" "math/rand" "regexp" "strconv" "strings" + "time" + + "github.com/google/uuid" + "github.com/sssvip/goutil/logutil" ) //NewUUID 返回UUID @@ -116,3 +118,22 @@ func RandNumAlphabet(textLen int) string { //32位以内 } return buffer.String()[:textLen] } + +func IntWithDefault(text int, defalut string) string { + if text == 0 { + return defalut + } + return strconv.Itoa(text) +} + +func StringWithDefault(text, defalut string) string { + if text == "" { + return defalut + } + return text +} + +func UnixNanoStrWithLen(numLen int) string { + s := Format("%v", time.Now().UnixNano()) + return s[:numLen] +}