-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathutil.go
More file actions
35 lines (31 loc) · 775 Bytes
/
util.go
File metadata and controls
35 lines (31 loc) · 775 Bytes
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
package tool
import (
"fmt"
"net/url"
"os"
"path/filepath"
"strings"
)
func CurrentDir(joinPath ...string) (string, error) {
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
return "", err
}
p := strings.Replace(dir, "\\", "/", -1)
whole := filepath.Join(joinPath...)
whole = filepath.Join(p, whole)
return whole, nil
}
func ResolveURL(u *url.URL, p string) string {
var Url, err = u.Parse(p)
if err != nil {
panic(err)
}
return Url.String()
}
func DrawProgressBar(prefix string, proportion float32, width int, suffix ...string) {
pos := int(proportion * float32(width))
s := fmt.Sprintf("[%s] %s%*s %6.2f%% %s",
prefix, strings.Repeat("■", pos), width-pos, "", proportion*100, strings.Join(suffix, ""))
fmt.Print("\r" + s)
}