generated from alexejk/go-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(client): Allow custom headers (#9)
Support for better options for the `Client` including custom headers. Docs & Changelog update Co-authored-by: Alexej Kubarev <[email protected]>
- Loading branch information
Showing
9 changed files
with
297 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package xmlrpc | ||
|
||
import "net/http" | ||
|
||
// Option is a function that configures a Client by mutating it | ||
type Option func(client *Client) | ||
|
||
// Headers option allows setting custom headers that will be passed with every request | ||
func Headers(headers map[string]string) Option { | ||
return func(client *Client) { | ||
client.codec.customHeaders = headers | ||
} | ||
} | ||
|
||
// HttpClient option allows setting custom HTTP Client to be used for every request | ||
func HttpClient(httpClient *http.Client) Option { | ||
return func(client *Client) { | ||
client.codec.httpClient = httpClient | ||
} | ||
} | ||
|
||
// UserAgent option allows setting custom User-Agent header. | ||
// This is a convenience method when only UA needs to be modified. For other cases use Headers option. | ||
func UserAgent(userAgent string) Option { | ||
return func(client *Client) { | ||
client.codec.userAgent = userAgent | ||
} | ||
} |
Oops, something went wrong.