Skip to content

Commit 587fb5d

Browse files
committed
ok
1 parent f74b60e commit 587fb5d

File tree

4 files changed

+11
-45
lines changed

4 files changed

+11
-45
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fmt:
2424

2525

2626
crab:
27-
go build -gcflags="-N -l" -o bin/$@ -ldflags '$(LDFLAGS)' ./main.go
27+
go build -o bin/$@ -ldflags '$(LDFLAGS)' ./main.go
2828

2929

3030
test:

handler/handler.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,19 @@ func (s *server) iface(w http.ResponseWriter, r *http.Request) (i iface, ok bool
135135
path := r.Method + r.URL.Path
136136

137137
if i, ok = s.path[path]; ok {
138-
log.Debugf("find path:%v", path)
138+
//log.Debugf("find path:%v", path)
139139
return
140140
}
141141

142142
//如果完全匹配没找到,再找前缀的
143143
s.prefix.AscendGreaterOrEqual(&iface{path: path}, func(item btree.Item) bool {
144144
i = *(item.(*iface))
145145
ok = strings.HasPrefix(path, i.path)
146-
log.Debugf("path:%v, ipath:%v, ok:%v", path, i.path, ok)
146+
// log.Debugf("path:%v, ipath:%v, ok:%v", path, i.path, ok)
147147
return !ok
148148
})
149149

150-
log.Debugf("find prefix:%v, ok:%v", path, ok)
150+
// log.Debugf("find prefix:%v, ok:%v", path, ok)
151151
return
152152
}
153153

@@ -176,18 +176,7 @@ func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
176176

177177
log.Debugf("%v %v %v %v", r.RemoteAddr, r.Method, r.URL, i.path)
178178

179-
for j:=0; j<10; j++ {
180-
fmt.Printf("========%p\n", reflect.New(i.source).Interface())
181-
log.Debugf("new:%p", reflect.New(i.source).Interface())
182-
}
183-
184-
newObj := reflect.New(i.source)
185-
fmt.Printf("obj:%p\n", newObj)
186-
method := newObj.MethodByName(r.Method)
187-
callback := method.Interface().(func(http.ResponseWriter, *http.Request))
188-
189-
// callback := .MethodByName(r.Method).Interface()
190-
179+
callback := reflect.New(i.source).MethodByName(r.Method).Interface().(func(http.ResponseWriter, *http.Request))
191180
callback(w, nr)
192181

193182
return

main.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,23 @@ import (
55
"fmt"
66
"net"
77
"net/http"
8-
"time"
98

109
"github.com/dearcode/crab/handler"
1110
_ "github.com/dearcode/crab/server"
1211
)
1312

1413
type index struct {
14+
r *http.Request
15+
}
16+
17+
func test(r *http.Request) {
18+
fmt.Printf("%v\n", r.RemoteAddr)
1519
}
1620

1721
func (i *index) GET(w http.ResponseWriter, req *http.Request) {
1822
fmt.Printf("index:%p\n", i)
23+
test(req)
1924
w.Write([]byte("ok"))
20-
time.Sleep(time.Minute)
21-
2225
}
2326

2427
func main() {

v.go

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

0 commit comments

Comments
 (0)