Browse Source

fix: windows support qrcode

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

40
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()
}
}
}
}

Loading…
Cancel
Save