Compare commits
3 Commits
Author | Date | ||
---|---|---|---|
![]() |
6e98ac9100 | ||
![]() |
e21dbcc61b | ||
![]() |
906d43322e |
24
str.go
24
str.go
@ -6,6 +6,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -16,7 +17,10 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// get random number string with length.
|
// get random number string with length.
|
||||||
func GetRandomString(l int) string {
|
var GetRandomString = GetRandomNumString
|
||||||
|
|
||||||
|
// get random number string with length.
|
||||||
|
func GetRandomNumString(l int) string {
|
||||||
str := NUMBERSTRING
|
str := NUMBERSTRING
|
||||||
bytes := []byte(str)
|
bytes := []byte(str)
|
||||||
result := []byte{}
|
result := []byte{}
|
||||||
@ -101,6 +105,7 @@ func JsonstrToStrMap(jsonstr string) (m map[string]string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// string to string map to string
|
// string to string map to string
|
||||||
|
//
|
||||||
// example: "K1:V1;K2:V2"
|
// example: "K1:V1;K2:V2"
|
||||||
// => {K1:V1, K2:V2}
|
// => {K1:V1, K2:V2}
|
||||||
func StringToStrMap(str string, sep1, sep2 string) (m map[string]string) {
|
func StringToStrMap(str string, sep1, sep2 string) (m map[string]string) {
|
||||||
@ -112,3 +117,20 @@ func StringToStrMap(str string, sep1, sep2 string) (m map[string]string) {
|
|||||||
}
|
}
|
||||||
return m
|
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