Skip to content

v3.13.0

Compare
Choose a tag to compare
@joeig joeig released this 21 Sep 14:25
· 13 commits to main since this release

New

  • New with functional options (#93).

Deprecate

  • NewClient is now deprecated and will be removed with the next major release (#93). Please see the migration path below. NewClient internally uses New.

How do I migrate NewClient to New?

The functionality of NewClient and New is identical, but their signature is not. This is the function signature of NewClient:

// Deprecated!
func NewClient(baseURL string, vHost string, headers map[string]string, httpClient *http.Client) *Client

New replaces the headers and httpClient parameters with options:

func New(baseURL string, vHost string, options ...NewOption) *Client

Possible options:

func WithHeaders(headers map[string]string) NewOption // Corresponds to the `headers` parameter
func WithHTTPClient(httpClient *http.Client) NewOption // Corresponds to the `httpClient` parameter
func WithAPIKey(key string) NewOption // Corresponds to the `headers` parameter with `map[string]string{"X-API-Key": key}`

I need neither an API key, custom headers, nor a custom http.Client.

Omit the options completely.

- client := powerdns.NewClient("http://localhost:80", "localhost", nil, nil)
+ client := powerdns.New("http://localhost:80", "localhost")

I only need the X-API-Key header.

Use the WithAPIKey option.

- client := powerdns.NewClient("http://localhost:80", "localhost", map[string]string{"X-API-Key": "apipw"}, nil)
+ client := powerdns.New("http://localhost:80", "localhost", powerdns.WithAPIKey("apipw"))

I need custom headers and a custom http.Client.

Use the WithHeaders and WithHTTPClient options.

- client := powerdns.NewClient("http://localhost:80", "localhost", map[string]string{"X-Custom": "foo"}, &http.Client{})
+ client := powerdns.New("http://localhost:80", "localhost", powerdns.WithHeaders(map[string]string{"X-Custom": "foo"}), powerdns.WithHTTPClient(&http.Client{}))