-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttpserver_impl.go
More file actions
58 lines (53 loc) · 1.18 KB
/
httpserver_impl.go
File metadata and controls
58 lines (53 loc) · 1.18 KB
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
54
55
56
57
58
package httpserver
import (
"fmt"
"io"
"net/http"
"sync"
)
var _ = fmt.Println
type httpServerImpl struct {
m_urlParse urlParsePro
m_topicMap sync.Map
}
func (this *httpServerImpl) ServeHTTP(w http.ResponseWriter, r *http.Request) {
url := r.URL.String()
isFind, findTopic, params := this.m_urlParse.findMatch(&url)
if !isFind {
io.WriteString(w, "no subscribe")
return
}
v, ok := this.m_topicMap.Load(*findTopic)
if !ok {
io.WriteString(w, "not found methodMap")
return
}
methodMap := v.(sync.Map)
method := r.Method
v, ok = methodMap.Load(method)
if !ok {
io.WriteString(w, "method no subscribe")
return
}
var param urlParam
param.init()
param.set(params)
handler := v.(CRouterHandler)
res := handler.handler(w, r, ¶m, this)
if !res {
io.WriteString(w, "interior error")
}
}
func (this *httpServerImpl) Subscribe(topic string, method string, handler CRouterHandler) {
this.m_urlParse.regisnterUrl(topic)
v, ok := this.m_topicMap.Load(topic)
if !ok {
methodMap := sync.Map{}
methodMap.Store(method, handler)
this.m_topicMap.Store(topic, methodMap)
} else {
mp := v.(sync.Map)
mp.Store(method, handler)
this.m_topicMap.Store(topic, mp)
}
}