-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimplement.go
More file actions
43 lines (38 loc) · 874 Bytes
/
implement.go
File metadata and controls
43 lines (38 loc) · 874 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
package httpserver
import (
"fmt"
"io"
"net/http"
"sync"
)
var _ = fmt.Println
type httpServer struct {
m_routerMap sync.Map
m_urlParse urlParse
}
func (this *httpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
topic := r.URL.String()
var param urlParam
ok, v := this.m_urlParse.findMatch(&topic, &this.m_routerMap, ¶m)
if !ok {
io.WriteString(w, "no subscribe")
return
}
methodMap := v.(sync.Map)
method := r.Method
v, ok = methodMap.Load(method)
if !ok {
io.WriteString(w, "method no subscribe")
return
}
handler := v.(*routerHandler)
res := handler.handler(w, r, ¶m, this)
if !res {
io.WriteString(w, "interior error")
}
}
func (this *httpServer) Subscribe(topic string, method string, handler CRouterHandler) {
methodMap := sync.Map{}
methodMap.Store(method, handler)
this.m_routerMap.Store(topic, methodMap)
}