We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
https://samwho.dev/blog/api-design-optional-parameters/
API design is hard. A good API needs to be:
type options struct { followRedirects bool headers map[string]string } type Option = func(*options) var ( FollowRedirects = func(o *options) { o.followRedirects = true } Header = func(key, value string) func(*options) { return func(o *options) { o.headers[key] = value } } ) func Get(url string, os ...Option) (Response, error) { o := options{} for _, option := range os { option(&o) } // ... }
Some examples of using this:
rsp, err := http.Get("http://example.com")
If you want to specify parameters:
rsp, err := http.Get("http://example.com", http.FollowRedirects, http.Header("Accept-Encoding", "gzip"))
The text was updated successfully, but these errors were encountered:
No branches or pull requests
https://samwho.dev/blog/api-design-optional-parameters/
› Guiding principles
API design is hard. A good API needs to be:
› Go: adding parameters a better way
Some examples of using this:
If you want to specify parameters:
The text was updated successfully, but these errors were encountered: