rest: Add SetUserPass to create Authorization header
This commit is contained in:
parent
2453abfbea
commit
bcdd79320b
1 changed files with 9 additions and 0 deletions
|
@ -91,6 +91,15 @@ func (api *Client) SetSigner(signer SignerFn) *Client {
|
||||||
return api
|
return api
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetUserPass creates an Authorization header for all requests with
|
||||||
|
// the UserName and Password passed in
|
||||||
|
func (api *Client) SetUserPass(UserName, Password string) *Client {
|
||||||
|
req, _ := http.NewRequest("GET", "http://example.com", nil)
|
||||||
|
req.SetBasicAuth(UserName, Password)
|
||||||
|
api.SetHeader("Authorization", req.Header.Get("Authorization"))
|
||||||
|
return api
|
||||||
|
}
|
||||||
|
|
||||||
// Opts contains parameters for Call, CallJSON etc
|
// Opts contains parameters for Call, CallJSON etc
|
||||||
type Opts struct {
|
type Opts struct {
|
||||||
Method string // GET, POST etc
|
Method string // GET, POST etc
|
||||||
|
|
Loading…
Reference in a new issue