Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce functional options for NewClient #93

Closed
joeig opened this issue Sep 19, 2024 · 0 comments · Fixed by #94
Closed

Introduce functional options for NewClient #93

joeig opened this issue Sep 19, 2024 · 0 comments · Fixed by #94
Assignees

Comments

@joeig
Copy link
Owner

joeig commented Sep 19, 2024

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"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant