From 97fbb7d298bfd7dd9d5c80d697171c54045c1b5c Mon Sep 17 00:00:00 2001 From: Simon Richardson Date: Thu, 2 Apr 2020 12:27:26 +0100 Subject: [PATCH] Add code comments to help with Option understanding --- client/client.go | 3 +++ http/client.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/client/client.go b/client/client.go index 5c5d62d..38082b4 100644 --- a/client/client.go +++ b/client/client.go @@ -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 { diff --git a/http/client.go b/http/client.go index 3a66b47..db7b92b 100644 --- a/http/client.go +++ b/http/client.go @@ -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