From 6bf82e853f8169f1c239923101555efb512859ad Mon Sep 17 00:00:00 2001 From: dandyhuang Date: Tue, 5 Jan 2021 20:34:42 +0800 Subject: [PATCH] fix: windows support qrcode --- common/lib.go | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/common/lib.go b/common/lib.go index 6a6a2d0..74a0b3c 100644 --- a/common/lib.go +++ b/common/lib.go @@ -46,7 +46,7 @@ func Utf8ToGbk(s []byte) ([]byte, error) { } func NewRandStr(length int) string { - s:=[]string{ + s := []string{ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", @@ -57,20 +57,20 @@ func NewRandStr(length int) string { "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", } - str:="" - for i:=1;i<=length;i++ { + str := "" + for i := 1; i <= length; i++ { r := rand.New(rand.NewSource(time.Now().UnixNano())) - str+=s[r.Intn(len(s)-1)] + str += s[r.Intn(len(s)-1)] } return str } -func Substr(s string,start,end int) string { - strRune:=[]rune(s) - if start==-1 { +func Substr(s string, start, end int) string { + strRune := []rune(s) + if start == -1 { return string(strRune[:end]) } - if end==-1 { + if end == -1 { return string(strRune[start:]) } return string(strRune[start:end]) @@ -95,17 +95,17 @@ func Exists(path string) bool { return true } -func OpenImage(file string) { - if runtime.GOOS=="windows" { - cmd:=exec.Command("start",file) - _=cmd.Start() - }else{ - if runtime.GOOS=="linux" { - cmd:=exec.Command("eog",file) - _=cmd.Start() - }else{ - cmd:=exec.Command("open",file) - _=cmd.Start() +func OpenImage(file string) { + if runtime.GOOS == "windows" { + cmd := exec.Command("cmd", "/k", "start", file) + _ = cmd.Start() + } else { + if runtime.GOOS == "linux" { + cmd := exec.Command("eog", file) + _ = cmd.Start() + } else { + cmd := exec.Command("open", file) + _ = cmd.Start() } } -} \ No newline at end of file +}