alexejk / go-xmlrpc

An XML-RPC Client for Go
https://alexejk.io/article/handling-xmlrpc-in-go/
MIT License
19 stars 7 forks source link

feat(client): Allow custom headers #9

Closed Nightapes closed 4 years ago

alexejk commented 4 years ago

Thanks for the PR, @Nightapes ! I'm a bit concerned about adding another argument to NewClientXXX functions as this is probably not the best approach for each and every customization option that might need to happen. I would rather opt in for mutating the client with help of Options functions.

Something in the style of the following:


type Option func (c *Client)

func NewClient(endpoint string, opts ...Option) *Client {}

func HeadersOption(h map[string]string) Option {
  return func(c *Client) {
    // mutate Client
  }
}

Something like described here: https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis

This would mean we won't need NewClientWithHttpClient either, and that potentially can be removed in favor of func HttpClientOption(hc *http.Client) Option{}.

What are your thoughts on the above?

alexejk commented 4 years ago

I've applied the changes similar to described above and docs are updated.

alexejk commented 4 years ago

Thank you for the contribution, I've release v0.2.0 which contains a combination of your changes and my updates applied.

Nightapes commented 4 years ago

@alexejk i like the idea with the options, great job! Thanks for the fast release