mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-20 02:57:05 +00:00
[Rest Client] Use options for client.New (#463)
* adding in clientopts to the rest client Signed-off-by: Corey Aloia <corey.aloia@sap.com>
This commit is contained in:
38
pkg/rest/client/apiv1_client_opts.go
Normal file
38
pkg/rest/client/apiv1_client_opts.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
// options is a struct that holds the options for the rest client
|
||||
type options struct {
|
||||
transport http.RoundTripper
|
||||
timeout time.Duration
|
||||
}
|
||||
|
||||
type Option interface {
|
||||
apply(*options)
|
||||
}
|
||||
|
||||
func getDefaultOptions() *options {
|
||||
return &options{
|
||||
timeout: 30 * time.Second,
|
||||
}
|
||||
}
|
||||
|
||||
type transportOption struct {
|
||||
transport http.RoundTripper
|
||||
}
|
||||
|
||||
func (t transportOption) apply(opts *options) {
|
||||
opts.transport = t.transport
|
||||
}
|
||||
|
||||
// WithOptTransport sets the transport for the rest client.
|
||||
// Transport specifies the mechanism by which individual
|
||||
// HTTP requests are made.
|
||||
// If nil, http.DefaultTransport is used.
|
||||
func WithOptTransport(transport http.RoundTripper) Option {
|
||||
return transportOption{transport}
|
||||
}
|
||||
Reference in New Issue
Block a user