Skip to content

Introduce functional options for NewClient #93

@joeig

Description

@joeig
func NewClient(baseURL string, vHost string, headers map[string]string, httpClient *http.Client) *Client

headers and httpClient are often times nil. I propose to turn them to functional options to make the signature of NewClient more concise. There could be a dedicated option for X-API-Key.

func WithHeaders(headers map[string]string)
func WithHttpClient(client *http.Client)
func WithAPIKey(key string)
func NewClient(baseURL string, vHost string, opts ...NewClientOptions) *Client

Usage:

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions