Skip to content

Commit

Permalink
Add code comments to help with Option understanding
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonRichardson committed Apr 2, 2020
1 parent 50831ca commit 97fbb7d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ type AuthenticatingClient interface {
}

// Option allows the adaptation of a client given new options.
// Both client.Client and http.Client have Options. To allow isolation between
// layers, we have separate options. If client.Client and http.Client want
// different options they can do so, without causing conflict.
type Option func(*options)

type options struct {
Expand Down
6 changes: 6 additions & 0 deletions http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,18 @@ type HttpClient interface {
PostForm(url string, data url.Values) (resp *http.Response, err error)
}

// Option allows the adaptation of a http client given new options.
// Both client.Client and http.Client have Options. To allow isolation between
// layers, we have separate options. If client.Client and http.Client want
// different options they can do so, without causing conflict.
type Option func(*options)

type options struct {
headersFunc HeadersFunc
}

// WithHeadersFunc allows passing in a new headers func for the http.Client
// to execute for each request.
func WithHeadersFunc(headersFunc HeadersFunc) Option {
return func(options *options) {
options.headersFunc = headersFunc
Expand Down

0 comments on commit 97fbb7d

Please sign in to comment.