Created
March 31, 2019 20:30
-
-
Save deankarn/6abf7828fac4f3c290ab6fbb83b160bb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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