...
1
2
3 package urlx
4
5 import (
6 "net/url"
7 "path/filepath"
8 "strings"
9 )
10
11
12 func GetURLFilePath(u *url.URL) string {
13 if u == nil {
14 return ""
15 }
16 if !(u.Scheme == "file" || u.Scheme == "") {
17 return u.Path
18 }
19
20 fPath := u.Path
21 if u.Host != "" {
22
23 fPath = "\\\\" + u.Host + filepath.FromSlash(fPath)
24 return fPath
25 }
26 fPathTrimmed := strings.TrimLeft(fPath, "/")
27 if winPathRegex.MatchString(fPathTrimmed) {
28
29
30 fPath = fPathTrimmed
31 }
32 return filepath.FromSlash(fPath)
33 }
34
View as plain text