Documentation
¶
Overview ¶
This package aims to wrap Go HTTP Client's request-response with sane defaults:
- You are forced to consider timeouts by having to specify Context
- Instead of not considering non-2xx status codes as a failure, check that by default (unless explicitly asked to)
- Sending and receiving JSON requires much less boilerplate, and on receiving JSON you are forced to think whether to "allowUnknownFields"
Index ¶
- Variables
- func Del(ctx context.Context, url string, confPieces ...ConfigPiece) (*http.Response, error)
- func Get(ctx context.Context, url string, confPieces ...ConfigPiece) (*http.Response, error)
- func Head(ctx context.Context, url string, confPieces ...ConfigPiece) (*http.Response, error)
- func Post(ctx context.Context, url string, confPieces ...ConfigPiece) (*http.Response, error)
- func Put(ctx context.Context, url string, confPieces ...ConfigPiece) (*http.Response, error)
- type Config
- type ConfigHook
- type ConfigPiece
- func After(fn ConfigHook) ConfigPiece
- func AuthBasic(username, password string) ConfigPiece
- func AuthBearer(token string) ConfigPiece
- func Before(fn ConfigHook) ConfigPiece
- func Client(client *http.Client) ConfigPiece
- func Cookie(cookie http.Cookie) ConfigPiece
- func Header(key, val string) ConfigPiece
- func RespondsJson(ref interface{}, allowUnknownFields bool) ConfigPiece
- func SendBody(body io.Reader, contentType string) ConfigPiece
- func SendJson(ref interface{}) ConfigPiece
- type ResponseStatusError
Constants ¶
This section is empty.
Variables ¶
View Source
var (
DefaultTimeout10s = 10 * time.Second
)
View Source
var InsecureTlsClient = &http.Client{ Transport: &http.Transport{ TLSClientConfig: &tls.Config{ InsecureSkipVerify: true, }, }, }
View Source
var TolerateNon2xxResponse = After(func(conf *Config) { conf.TolerateNon2xxResponse = true })
Functions ¶
Types ¶
type ConfigHook ¶
type ConfigHook func(conf *Config)
type ConfigPiece ¶
type ConfigPiece struct {
BeforeInit ConfigHook
AfterInit ConfigHook
}
func After ¶
func After(fn ConfigHook) ConfigPiece
func AuthBasic ¶
func AuthBasic(username, password string) ConfigPiece
func AuthBearer ¶
func AuthBearer(token string) ConfigPiece
func Before ¶
func Before(fn ConfigHook) ConfigPiece
same as After(), but Config.Request is nil. used mainly for specifying request body, which must be known on call to http.NewRequest()
func Client ¶
func Client(client *http.Client) ConfigPiece
func Cookie ¶
func Cookie(cookie http.Cookie) ConfigPiece
func Header ¶
func Header(key, val string) ConfigPiece
func RespondsJson ¶
func RespondsJson(ref interface{}, allowUnknownFields bool) ConfigPiece
func SendJson ¶
func SendJson(ref interface{}) ConfigPiece
type ResponseStatusError ¶
type ResponseStatusError struct {
// contains filtered or unexported fields
}
func (ResponseStatusError) StatusCode ¶
func (e ResponseStatusError) StatusCode() int
returns the (non-2xx) status code that caused the error
Click to show internal directories.
Click to hide internal directories.