Browse Source

fix: windows support qrcode

main
dandyhuang 4 years ago
parent
commit
6bf82e853f
  1. 38
      common/lib.go

38
common/lib.go

@ -46,7 +46,7 @@ func Utf8ToGbk(s []byte) ([]byte, error) {
} }
func NewRandStr(length int) string { func NewRandStr(length int) string {
s:=[]string{ s := []string{
"a", "b", "c", "d", "e", "f", "a", "b", "c", "d", "e", "f",
"g", "h", "i", "j", "k", "l", "g", "h", "i", "j", "k", "l",
"m", "n", "o", "p", "q", "r", "m", "n", "o", "p", "q", "r",
@ -57,20 +57,20 @@ func NewRandStr(length int) string {
"Q", "R", "S", "T", "U", "V", "Q", "R", "S", "T", "U", "V",
"W", "X", "Y", "Z", "W", "X", "Y", "Z",
} }
str:="" str := ""
for i:=1;i<=length;i++ { for i := 1; i <= length; i++ {
r := rand.New(rand.NewSource(time.Now().UnixNano())) r := rand.New(rand.NewSource(time.Now().UnixNano()))
str+=s[r.Intn(len(s)-1)] str += s[r.Intn(len(s)-1)]
} }
return str return str
} }
func Substr(s string,start,end int) string { func Substr(s string, start, end int) string {
strRune:=[]rune(s) strRune := []rune(s)
if start==-1 { if start == -1 {
return string(strRune[:end]) return string(strRune[:end])
} }
if end==-1 { if end == -1 {
return string(strRune[start:]) return string(strRune[start:])
} }
return string(strRune[start:end]) return string(strRune[start:end])
@ -95,17 +95,17 @@ func Exists(path string) bool {
return true return true
} }
func OpenImage(file string) { func OpenImage(file string) {
if runtime.GOOS=="windows" { if runtime.GOOS == "windows" {
cmd:=exec.Command("start",file) cmd := exec.Command("cmd", "/k", "start", file)
_=cmd.Start() _ = cmd.Start()
}else{ } else {
if runtime.GOOS=="linux" { if runtime.GOOS == "linux" {
cmd:=exec.Command("eog",file) cmd := exec.Command("eog", file)
_=cmd.Start() _ = cmd.Start()
}else{ } else {
cmd:=exec.Command("open",file) cmd := exec.Command("open", file)
_=cmd.Start() _ = cmd.Start()
} }
} }
} }
Loading…
Cancel
Save