Train chains interceptors so that they can be plugged into any http.Client. For example, this chain will transparently, retry requests for temporary errors, log requests/responses and increment some request/response stats.

Interceptors are consulted in the order they are provided. You'll need to decide what order you want your interceptors to be called in.

// This chain will:// 1. Start monitoring errors.// 2. Log the request.// 3. Record stats about the request.// 4. Do HTTP.// 5. Record stats about the response.// 6. Log the response.// 7. Retry temporary errors, if any, and restart the chain at 2 in that case.transport:= train.Transport(errInterceptor, logInterceptor, statsInterceptor)
// This chain will:// 1. Log the request.// 2. Record stats about the request.// 3. Do HTTP.// 4. Retry temporary errors and return after all retries have been exhausted.// 5. Record stats about the response.// 6. Log the response.transport:= train.Transport(logInterceptor, statsInterceptor, errInterceptor)