-
-
Notifications
You must be signed in to change notification settings - Fork 120
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
Add basic auth support: Sling.SetBasicAuth() #16
Conversation
@@ -145,6 +146,20 @@ func (s *Sling) Set(key, value string) *Sling { | |||
return s | |||
} | |||
|
|||
// SetBasicAuth mimics http.Request.SetBasicAuth() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// SetBasicAuth sets the Authorization header to use HTTP Basic Authentication
// with the provided username and password. With HTTP Basic Authentication
// the provided username and password are not encrypted.
^ let's match net/http so its implicitly clear it does the same.
Simple enough to do it directly on the Otherwise, looks good for merge. Thanks for the PR. |
@dghubble Voilà, updated comments and added tests. You can indeed do it on the
So you can set your auth once when building your base client, then forget about it which is quite nice. Since sling is especially built for interacting with APIs it seemed odd that adding auth (required for all production APIs) was awkward or didn't follow the simplicity and ease of use elsewhere (automatic JSON serialization, etc ...) |
@dghubble Sorry for taking a few days to reply to your feedback. I got swamped with work. Let me know if you have any further questions. |
Squash merged as c1694aa. Thanks! |
Sling is one of the nicest libraries I found, it's composable and elegant. However I found it frustrating that it lacked Basic Auth support which is a must have when writing API clients, so I thought I would add here.
Tried to keep it as simple as possible and follow existing conventions (allow chaining etc ...)
Let me know if you have any questions.