Created
March 31, 2019 21:24
-
-
Save deankarn/4669c0c7fe8fc0577f0f7a0b757c4c42 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) (*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