-
-
Notifications
You must be signed in to change notification settings - Fork 46
/
util.go
58 lines (53 loc) · 1.01 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package engine
import (
"math/rand"
"os"
"time"
)
func GetArgs(args ...string) (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10 string) {
// at least one
if len(args) < 1 {
return "", "", "", "", "", "", "", "", "", ""
}
// parse args
for i, arg := range args {
switch i {
case 0:
arg1 = arg
case 1:
arg2 = arg
case 2:
arg3 = arg
case 3:
arg4 = arg
case 4:
arg5 = arg
case 5:
arg6 = arg
case 6:
arg7 = arg
case 7:
arg8 = arg
case 8:
arg9 = arg
case 9:
arg10 = arg
default:
}
}
return arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10
}
// RandomKey generate a random string key
func RandomKey(n int) string {
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890")
rand.Seed(time.Now().UnixNano())
b := make([]rune, n)
for i := range b {
b[i] = letterRunes[rand.Intn(len(letterRunes))]
}
return string(b)
}
func FileExist(path string) bool {
_, err := os.Lstat(path)
return !os.IsNotExist(err)
}