diff options
-rw-r--r-- | route.go | 6 | ||||
-rw-r--r-- | route_test.go | 5 | ||||
-rw-r--r-- | router.go | 16 | ||||
-rw-r--r-- | router_benchmark_test.go | 5 | ||||
-rw-r--r-- | router_test.go | 5 |
5 files changed, 17 insertions, 20 deletions
diff --git a/route.go b/route.go index 2fed631..0aea94c 100644 --- a/route.go +++ b/route.go @@ -6,7 +6,7 @@ import ( "github.com/franckcuny/web-request" ) -type fn func(*request.Request) (request.Response, error) +type fn func(*request.Request, *request.Response) (error) type fns map[string]fn type Route struct { @@ -108,8 +108,8 @@ L: } } -func (self *Route) Execute(request *request.Request) (request.Response, error) { - return self.Code(request) +func (self *Route) Execute(request *request.Request, response *request.Response) error { + return self.Code(request, response) } func (self *Route) init() { diff --git a/route_test.go b/route_test.go index 8159073..dd38e80 100644 --- a/route_test.go +++ b/route_test.go @@ -9,9 +9,8 @@ import ( "testing" ) -func testRoute(req *request.Request) (request.Response, error) { - resp := request.Response{} - return resp, nil +func testRoute(req *request.Request, resp *request.Response) error { + return nil } func TestBasic(t *testing.T) { diff --git a/router.go b/router.go index 85573df..13be84c 100644 --- a/router.go +++ b/router.go @@ -33,10 +33,10 @@ func (self *Router) AddOptions() *Router { for _, r := range routes { m := self.GetMethodsForPath(r) allowed := strings.Join(m, ", ") - defaultFn := func(req *request.Request) (request.Response, error) { - r := request.Response{Status: 204} - r.AddHeader("Allow", allowed) - return r, nil + defaultFn := func(req *request.Request, resp *request.Response) error { + resp.Status = 204 + resp.AddHeader("Allow", allowed) + return nil } self.AddRoute(&Route{Method: "OPTIONS", Path: r, Code: defaultFn}) } @@ -54,10 +54,10 @@ func (self *Router) AddNotAllowed() *Router { supportedMethods[m] = true } allowed := strings.Join(methods, ", ") - defaultFn := func(req *request.Request) (request.Response, error) { - r := request.Response{Status: 405} - r.AddHeader("Allow", allowed) - return r, nil + defaultFn := func(req *request.Request, resp *request.Response) error { + resp.Status = 405 + resp.AddHeader("Allow", allowed) + return nil } for _, dm := range defaultHTTPMethods { if supportedMethods[dm] == false { diff --git a/router_benchmark_test.go b/router_benchmark_test.go index 42fe579..222b72e 100644 --- a/router_benchmark_test.go +++ b/router_benchmark_test.go @@ -8,9 +8,8 @@ import ( "testing" ) -func testSimpleRoute(req *request.Request) (request.Response, error) { - resp := request.Response{} - return resp, nil +func testSimpleRoute(req *request.Request, resp *request.Response) error { + return nil } func BenchmarkSimple(b *testing.B) { diff --git a/router_test.go b/router_test.go index 71fdcaf..167468f 100644 --- a/router_test.go +++ b/router_test.go @@ -7,9 +7,8 @@ import ( "testing" ) -func testRouter(req *request.Request) (request.Response, error) { - resp := request.Response{} - return resp, nil +func testRouter(req *request.Request, resp *request.Response) error { + return nil } func testBasic(t *testing.T) { |