Skip to content

v2.1.0

Compare
Choose a tag to compare
@ant0ine ant0ine released this 30 Nov 19:32
· 193 commits to master since this release

Main changes

  • Apache-style access log
  • Improved timer and recorder middlewares
  • new JSONP middleware
  • Make the gzip middleware support streaming responses

Apache-style access log

Go-Json-Rest now reuses the well known Apache log formatting syntax to define the access log.

With this new feature, the user can define his own record format:

rest.ResourceHandler{
        LoggerFormat: "%t %r %s %b",
}

or pick a predefined one:

rest.ResourceHandler{
        LoggerFormat: rest.CommonLogFormat,
}

or just just ignore this field and get a default, development friendly access log.

This is an implementation of a subset of the Apache mod_log_config syntax. Some options are not implemented yet, I expect the support can grow over time.
See http://httpd.apache.org/docs/2.0/mod/mod_log_config.html for reference.
And See Godoc for the list of supported options and predefined formats: https://godoc.org/github.com/ant0ine/go-json-rest/rest#AccessLogFormat

Note: Compatibility with the existing JSON logging is maintained. This JSON logging feature may be deprecated in the future is favor of a more powerful one. Internally, logMiddleware is replaced by accessLogApacheMiddleware and accessLogJsonMiddleware.

Improved timer and recorder middlewares

  • timerMiddleware now populates request.Env["START_TIME"]
  • recorderMiddleware now records request.Env["BYTES_WRITTEN"]
  • tests have been added to both

JSONP middleware

This is a new public middleware that can be instantiated like this:

    handler := rest.ResourceHandler{
        PreRoutingMiddlewares: []rest.Middleware{
            &rest.JsonpMiddleware{
                CallbackNameKey: "cb",
            },
        },
    }

See the complete example here: https://github.com/ant0ine/go-json-rest#jsonp

Make the gzip middleware support streaming responses

The gzip Writer is now instantiated once per response, allowing multiple calls to response.Write() or response.WriteJson().
See the streaming example here: https://github.com/ant0ine/go-json-rest#streaming