Skip to content

Instantly share code, notes, and snippets.

@deankarn
Created March 31, 2019 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deankarn/6abf7828fac4f3c290ab6fbb83b160bb to your computer and use it in GitHub Desktop.
Save deankarn/6abf7828fac4f3c290ab6fbb83b160bb to your computer and use it in GitHub Desktop.
package mylib
import "net/http"
// New create a new Instance of mylib
func New(someAlwaysRequiredValue string, options ...func(*Instance) error) (*Instance, error) {
return &Instance{
client: new(http.Client), // default no auth client
}, nil
}
type Instance struct {
client *http.Client
}
// BasicAuth creates a function that sets the username and password for requests when passed as an options function.
func BasicAuth(username, password string) func(*Instance) error{
return func(i *Instance) error {
// create an http client where the basic credentials
// are injected automatically into requests.
client,err := //...
if err != nil {
return err
}
i.client = client
return nil
}
}
// OAuth ...
func OAuth(id, secret string) func(*Instance) error{
// ....
return func(i *Instance) error {
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment