Improved API
This commit is contained in:
14
Server.go
14
Server.go
@ -42,8 +42,8 @@ func New() Server {
|
||||
handlers: []Handler{
|
||||
func(c Context) error {
|
||||
ctx := c.(*ctx)
|
||||
method := ctx.Method()
|
||||
path := ctx.Path()
|
||||
method := ctx.request.Method()
|
||||
path := ctx.request.Path()
|
||||
handler := ctx.server.router.LookupNoAlloc(method, path, ctx.addParameter)
|
||||
|
||||
if handler == nil {
|
||||
@ -54,8 +54,8 @@ func New() Server {
|
||||
},
|
||||
},
|
||||
errorHandler: func(ctx Context, err error) {
|
||||
ctx.WriteString(err.Error())
|
||||
log.Println(ctx.Path(), err)
|
||||
ctx.Response().WriteString(err.Error())
|
||||
log.Println(ctx.Request().Path(), err)
|
||||
},
|
||||
}
|
||||
|
||||
@ -90,10 +90,10 @@ func (s *server) Put(path string, handler Handler) {
|
||||
}
|
||||
|
||||
// ServeHTTP responds to the given request.
|
||||
func (s *server) ServeHTTP(response http.ResponseWriter, request *http.Request) {
|
||||
func (s *server) ServeHTTP(res http.ResponseWriter, req *http.Request) {
|
||||
ctx := s.pool.Get().(*ctx)
|
||||
ctx.request = request
|
||||
ctx.response = response
|
||||
ctx.request = request{req}
|
||||
ctx.response = response{res}
|
||||
err := s.handlers[0](ctx)
|
||||
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user