Skip to content

Instantly share code, notes, and snippets.

@deankarn
Created March 31, 2019 21:24
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/4669c0c7fe8fc0577f0f7a0b757c4c42 to your computer and use it in GitHub Desktop.
Save deankarn/4669c0c7fe8fc0577f0f7a0b757c4c42 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) (*Builder, error) {
return &Builder{
// some nice sane defaults if necessary
}, nil
}
// Builder configures Instance to be built
type Builder struct {
username string
password string
}
// BasicAuth creates a function that sets the username and password for requests when passed as an options function.
func (b *Builder) BasicAuth(username, password string) *Builder {
b.username = username
b.password = password
return b
}
// OAuth ...
func (b *Builder) OAuth(id, secret string) *Builder {
//b.id = id
//b.secret = secret
return b
}
// builds the final Instance
func (b *Builder) Build() (*Instance, error) {
// create an http client where the basic credentials
// are injected automatically into requests.
client,err := //...
if err != nil {
return err
}
return &Instance{
client: client,
}, nil
}
type Instance struct {
client *http.Client
}
func(i *Instance) MyRuntimeOnlyMethod() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment