|
@@ -8,17 +8,30 @@ import (
|
|
|
"log"
|
|
|
"math/rand"
|
|
|
"os"
|
|
|
+ "path"
|
|
|
"runtime"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
+var root string
|
|
|
+
|
|
|
+func SetRoot() {
|
|
|
+ if strings.HasPrefix(os.Args[0], os.TempDir()) {
|
|
|
+ root = Cwd(2) + "/"
|
|
|
+ } else {
|
|
|
+ f, _ := os.Executable()
|
|
|
+ root = path.Dir(f) + "/"
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func Cwd(i int) string {
|
|
|
_, fp, _, _ := runtime.Caller(i)
|
|
|
slice := strings.Split(fp, "/")
|
|
|
slice = slice[:len(slice)-1]
|
|
|
path := strings.Join(slice, "/")
|
|
|
+ path = strings.Replace(path, root, "", 1)
|
|
|
return path
|
|
|
}
|
|
|
|