| 1 |
package main |
| 2 |
|
| 3 |
import ( |
| 4 |
"net/http" |
| 5 |
"net/http/httptest" |
| 6 |
) |
| 7 |
|
| 8 |
type T struct { |
| 9 |
name string |
| 10 |
next http.Handler |
| 11 |
} |
| 12 |
|
| 13 |
func (t *T) ServeHTTP(rw http.ResponseWriter, req *http.Request) { |
| 14 |
println("in T.ServeHTTP") |
| 15 |
if t.next != nil { |
| 16 |
t.next.ServeHTTP(rw, req) |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
func New(name string, next http.Handler) (http.Handler, error) { return &T{name, next}, nil } |
| 21 |
|
| 22 |
func main() { |
| 23 |
next := func(rw http.ResponseWriter, req *http.Request) { |
| 24 |
println("in next") |
| 25 |
} |
| 26 |
|
| 27 |
t, err := New("test", http.HandlerFunc(next)) |
| 28 |
if err != nil { |
| 29 |
panic(err) |
| 30 |
} |
| 31 |
|
| 32 |
recorder := httptest.NewRecorder() |
| 33 |
req := httptest.NewRequest(http.MethodGet, "/", nil) |
| 34 |
t.ServeHTTP(recorder, req) |
| 35 |
println(recorder.Result().Status) |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|