Compare commits
No commits in common. "master" and "v1.0.2" have entirely different histories.
30
str.go
30
str.go
@ -6,7 +6,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@ -17,10 +16,7 @@ const (
|
||||
)
|
||||
|
||||
// get random number string with length.
|
||||
var GetRandomString = GetRandomNumString
|
||||
|
||||
// get random number string with length.
|
||||
func GetRandomNumString(l int) string {
|
||||
func GetRandomString(l int) string {
|
||||
str := NUMBERSTRING
|
||||
bytes := []byte(str)
|
||||
result := []byte{}
|
||||
@ -43,7 +39,7 @@ func GetRandomCharString(l int) string {
|
||||
return string(result)
|
||||
}
|
||||
|
||||
// skip
|
||||
//skip
|
||||
func Skip(s string, sep string, n int) string {
|
||||
seplen := len(sep)
|
||||
if seplen == 0 || n < 0 {
|
||||
@ -105,9 +101,8 @@ func JsonstrToStrMap(jsonstr string) (m map[string]string) {
|
||||
}
|
||||
|
||||
// string to string map to string
|
||||
//
|
||||
// example: "K1:V1;K2:V2"
|
||||
// => {K1:V1, K2:V2}
|
||||
// example: "K1:V1;K2:V2"
|
||||
// => {K1:V1, K2:V2}
|
||||
func StringToStrMap(str string, sep1, sep2 string) (m map[string]string) {
|
||||
m = map[string]string{}
|
||||
for _, kvstr := range strings.Split(str, sep1) {
|
||||
@ -117,20 +112,3 @@ func StringToStrMap(str string, sep1, sep2 string) (m map[string]string) {
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// get os env with default
|
||||
func GetEnvDefault(key, defval string) string {
|
||||
if val, ok := os.LookupEnv(key); ok {
|
||||
return val
|
||||
} else {
|
||||
return defval
|
||||
}
|
||||
}
|
||||
|
||||
// fix hex string to no 0x prefix
|
||||
func FixToNo0x(hexstr string) string {
|
||||
if strings.HasPrefix(hexstr, "0x") {
|
||||
return hexstr[2:]
|
||||
}
|
||||
return hexstr
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user