-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.go
41 lines (37 loc) · 805 Bytes
/
util.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
package lookup
// HasPath is an interface used to determine if a Pathor has a Path() function
type HasPath interface {
Path() string
}
// ExtractPath retrieves the path use because I didn't export it.
func ExtractPath(pather Pathor) string {
if p, ok := pather.(HasPath); ok {
return p.Path()
}
switch pather := pather.(type) {
case *Invalidor:
return pather.path
case *Constantor:
return pather.path
case *Reflector:
return pather.path
case *Interfaceor:
return pather.path
}
return "unknown"
}
type CustomPath interface {
Path(previousPath string, findPath string) string
}
func PathBuilder(path string, r Pathor, cp CustomPath) string {
p := ExtractPath(r)
if cp != nil {
return cp.Path(p, path)
}
if len(p) > 0 {
p = p + "." + path
} else {
p = path
}
return p
}