-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_paths.go
47 lines (37 loc) · 903 Bytes
/
utils_paths.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
package glog
import (
"net/url"
"path/filepath"
"regexp"
)
type PathType int
const (
INVALID_PATH PathType = iota
FILE_PATH
URL_PATH
)
func identifyPath(path string) PathType {
// Check if the input string is a URL
u, err := url.Parse(path)
if err == nil && u.Scheme != "" && u.Opaque == "" {
return URL_PATH
}
if len(path) > 0 && string(path[0]) == "/" && filepath.Clean(path) != "." {
return FILE_PATH
}
// Check if the input string is a Windows file path
if match, _ := regexp.MatchString(`^[a-zA-Z]:\\`, path); match {
return FILE_PATH
}
// If the input string is neither a URL nor a file path, it is something else
return INVALID_PATH
}
func IsURL(path string) bool {
return identifyPath(path) == URL_PATH
}
func IsFile(path string) bool {
return identifyPath(path) == FILE_PATH
}
func IsValidPath(path string) bool {
return identifyPath(path) != INVALID_PATH
}