-
Notifications
You must be signed in to change notification settings - Fork 34
/
location_pattern_types.go
53 lines (47 loc) · 1.28 KB
/
location_pattern_types.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
package teaconfigs
import "github.com/iwind/TeaGo/maps"
// 匹配类型
type LocationPatternType = int
// 内置的匹配类型定义
const (
LocationPatternTypePrefix = 1
LocationPatternTypeExact = 2
LocationPatternTypeRegexp = 3
)
// 取得所有的匹配类型信息
func AllLocationPatternTypes() []maps.Map {
return []maps.Map{
{
"name": "匹配前缀",
"type": LocationPatternTypePrefix,
"description": "带有此前缀的路径才会被匹配",
},
{
"name": "精准匹配",
"type": LocationPatternTypeExact,
"description": "带此路径完全一样的路径才会被匹配",
},
{
"name": "正则表达式匹配",
"type": LocationPatternTypeRegexp,
"description": "通过正则表达式来匹配路径,<a href=\"http://teaos.cn/doc/regexp/Regexp.md\" target=\"_blank\">正则表达式语法 »</a>",
},
}
}
// 查找单个匹配类型信息
func FindLocationPatternType(patternType int) maps.Map {
for _, t := range AllLocationPatternTypes() {
if t["type"] == patternType {
return t
}
}
return nil
}
// 查找单个匹配类型名称
func FindLocationPatternTypeName(patternType int) string {
t := FindLocationPatternType(patternType)
if t == nil {
return ""
}
return t["name"].(string)
}