-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebNode.go
56 lines (48 loc) · 902 Bytes
/
webNode.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
package main
import (
"regexp"
"time"
)
var dirParentRegex *regexp.Regexp
var fileParentRegex *regexp.Regexp
func init() {
dirParentRegex = regexp.MustCompile(`(.*\/).*\/`)
fileParentRegex = regexp.MustCompile(`(.*\/).*`)
}
type NodeType bool
const (
file NodeType = false
directory NodeType = true
)
type NodeStatus int8
const (
pending NodeStatus = iota
busy
done
)
type WebNode struct {
nodeStatus NodeStatus
nodeType NodeType
nodeFail bool
nodeDepth int
nodeLastSibling bool
path string
name string
time *time.Time
size int64
description string
}
func (w *WebNode) GetParentPath() (result string) {
var regexResult []string
switch w.nodeType {
case file:
regexResult = fileParentRegex.FindStringSubmatch(w.path)
case directory:
regexResult = dirParentRegex.FindStringSubmatch(w.path)
}
if regexResult == nil {
return ""
} else {
return regexResult[1]
}
}