Skip to content

Commit

Permalink
chore: add some funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
sssvip committed Jul 14, 2020
1 parent dbff0e2 commit b13d9ea
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions strutil/strutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
}

0 comments on commit b13d9ea

Please sign in to comment.