Recorder

A response recorder is one of the Iris specific http.ResponseWriter. It records the response body, status code and headers that you can manipulate at any handler inside a route's handlers chain.

  1. Call Context.Record() before send data.

  2. The Context.Recorder() returns a ResponseRecorder. Its methods can be used to manipulate or retrieve the response.

The ResponseRecorder type contains the standard Iris ResponseWriter methods plus the following methods.

Body returns the body tracked from the writer so far. Do not use this for edit.

Body() []byte

Use this to clear the body.

ResetBody()

Use Write/Writef/WriteString to stream write and SetBody/SetBodyString to set body instead.

Write(contents []byte) (int, error)

Writef(format string, a ...interface{}) (n int, err error)

WriteString(s string) (n int, err error)

SetBody(b []byte)

SetBodyString(s string)

Reset headers to their original state, before Context.Record call.

Clear all headers.

Reset resets the response body, headers and the status code header.

Example

Record operation log in global Interceptor.

Register the routes...

Or to remove the need of ctx.Next in your main handlers, modify the Iris handlers execution rules as follows.

In addition to that, Iris provides a comprehensive API for Transactions. Learn more about it by running an example.

Last updated

Was this helpful?