-
Notifications
You must be signed in to change notification settings - Fork 56
/
alias.go
49 lines (38 loc) · 1012 Bytes
/
alias.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
package serverHandler
import (
"mjpclab.dev/ghfs/src/util"
"strings"
)
type alias struct {
url string
fs string
}
func createAlias(urlPath, fsPath string) alias {
return alias{urlPath, fsPath}
}
func (alias alias) isMatch(rawReqPath string) bool {
return util.IsPathEqual(alias.url, rawReqPath)
}
func (alias alias) isSuccessorOf(rawReqPath string) bool {
return len(alias.url) > len(rawReqPath) && util.HasUrlPrefixDir(alias.url, rawReqPath)
}
func (alias alias) isPredecessorOf(rawReqPath string) bool {
return len(rawReqPath) > len(alias.url) && util.HasUrlPrefixDir(rawReqPath, alias.url)
}
func (alias alias) nextPartOf(rawReqPath string) (subName string, noMore, ok bool) {
if !alias.isSuccessorOf(rawReqPath) {
return
}
subName = alias.url[len(rawReqPath):]
if len(subName) > 0 && subName[0] == '/' {
subName = subName[1:]
}
slashIndex := strings.IndexByte(subName, '/')
if slashIndex > 0 {
subName = subName[:slashIndex]
} else {
noMore = true
}
ok = true
return
}