-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurlparse.go
More file actions
52 lines (48 loc) · 974 Bytes
/
urlparse.go
File metadata and controls
52 lines (48 loc) · 974 Bytes
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
package httpserver
import (
"fmt"
"regexp"
"strings"
"sync"
)
var _ = fmt.Println
type urlParse struct {
}
func (*urlParse) findMatch(topic *string, subscribes *sync.Map, param *urlParam) (bool, interface{}) {
var isExist bool = false
var resultValue interface{} = nil
inTopics := strings.Split(*topic, "/")
inTopicLen := len(inTopics)
f := func(k, v interface{}) bool {
subscribeTopic := k.(string)
topics := strings.Split(subscribeTopic, "/")
topicLen := len(topics)
if inTopicLen != topicLen {
return true
}
for i, t := range topics {
exp, err := regexp.Compile(":(.*)?")
if err != nil {
continue
}
r := exp.FindStringSubmatch(t)
rLen := len(r)
inT := inTopics[i]
if rLen == 2 {
param.add(&(r[1]), &inT)
} else {
if t != inT {
return true
}
}
}
isExist = true
resultValue = v
return false
}
subscribes.Range(f)
if isExist == false {
return false, nil
}
return true, resultValue
}