Skip to content

Commit 6fb915e

Browse files
committed
refactor(serverHandler): simplify alias into one type
1 parent 073d2f8 commit 6fb915e

File tree

13 files changed

+88
-405
lines changed

13 files changed

+88
-405
lines changed

src/serverHandler/alias.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package serverHandler
2+
3+
import (
4+
"../util"
5+
"strings"
6+
)
7+
8+
type alias struct {
9+
url string
10+
fs string
11+
}
12+
13+
func createAlias(urlPath, fsPath string) alias {
14+
return alias{urlPath, fsPath}
15+
}
16+
17+
func (alias alias) isMatch(rawReqPath string) bool {
18+
return util.IsPathEqual(alias.url, rawReqPath)
19+
}
20+
21+
func (alias alias) isSuccessorOf(rawReqPath string) bool {
22+
return len(alias.url) > len(rawReqPath) && util.HasUrlPrefixDir(alias.url, rawReqPath)
23+
}
24+
25+
func (alias alias) isPredecessorOf(rawReqPath string) bool {
26+
return len(rawReqPath) > len(alias.url) && util.HasUrlPrefixDir(rawReqPath, alias.url)
27+
}
28+
29+
func (alias alias) nextPartOf(rawReqPath string) (subName string, noMore, ok bool) {
30+
if !alias.isSuccessorOf(rawReqPath) {
31+
return
32+
}
33+
34+
subName = alias.url[len(rawReqPath):]
35+
if len(subName) > 0 && subName[0] == '/' {
36+
subName = subName[1:]
37+
}
38+
39+
slashIndex := strings.IndexByte(subName, '/')
40+
if slashIndex > 0 {
41+
subName = subName[:slashIndex]
42+
} else {
43+
noMore = true
44+
}
45+
46+
ok = true
47+
48+
return
49+
}

src/serverHandler/aliasAccurate.go

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/serverHandler/aliasNoCase.go

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/serverHandler/aliasNoCase_test.go

Lines changed: 0 additions & 218 deletions
This file was deleted.

src/serverHandler/alias_common.go

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)