github.com/blend/go-sdk@v1.20240719.1/r2/opt_on_response.go (about) 1 /* 2 3 Copyright (c) 2024 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package r2 9 10 import ( 11 "net/http" 12 "time" 13 ) 14 15 // OnResponseListener is an on response listener. 16 // 17 // The time.Time is given as the start time of the request in the UTC timezone. To compute the elapsed time 18 // you would subtract from the current time in UTC i.e. `time.Now().UTC().Sub(startTime)`. 19 type OnResponseListener func(*http.Request, *http.Response, time.Time, error) error 20 21 // OptOnResponse adds an on response listener. 22 // If an OnResponse listener has already been addded, it will be merged with the existing listener. 23 func OptOnResponse(listener OnResponseListener) Option { 24 return func(r *Request) error { 25 r.OnResponse = append(r.OnResponse, listener) 26 return nil 27 } 28 }