Files
moxa/_test/cli8.go
Marc Vertes e003140c6e interp: improve internal handling of functions
Up to now functions could be stored as node values in frame (as for interpreter defined functions) or function values, directly callable by the Go runtime. We now always store functions in the later form, making the processing of functions, anonymous closures and methods simpler and more robust. All functions, once compiled are always directly callable, with no further wrapping necessary.

Fixes #1459.
2022-10-19 17:54:08 +02:00

42 lines
738 B
Go

package main
import (
"net/http"
"net/http/httptest"
)
type T struct {
name string
next http.Handler
}
func (t *T) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
println("in T.ServeHTTP")
if t.next != nil {
t.next.ServeHTTP(rw, req)
}
}
func New(name string, next http.Handler) (http.Handler, error) { return &T{name, next}, nil }
func main() {
next := func(rw http.ResponseWriter, req *http.Request) {
println("in next")
}
t, err := New("test", http.HandlerFunc(next))
if err != nil {
panic(err)
}
recorder := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/", nil)
t.ServeHTTP(recorder, req)
println(recorder.Result().Status)
}
// Output:
// in T.ServeHTTP
// in next
// 200 OK