Documentation
¶
Index ¶
- func ContextRequestID(ctx context.Context) string
- func ContextWithRequestID(ctx context.Context) (context.Context, string)
- func HandleResponse(c *Client, resp *http.Response, pretty bool)
- func SetContextRequestID(ctx context.Context, reqID string) context.Context
- func WSRead(ws *websocket.Conn)
- func WSWrite(ws *websocket.Conn)
- type APIKeySigner
- type BasicSigner
- type Client
- type Doer
- type JWTSigner
- type OAuth2Signer
- type Signer
- type StaticToken
- type StaticTokenSource
- type Token
- type TokenSource
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextRequestID ¶
ContextRequestID extracts the Request ID from the context.
func ContextWithRequestID ¶
ContextWithRequestID returns ctx and the request ID if it already has one or creates and returns a new context with a new request ID.
func HandleResponse ¶
HandleResponse logs the response details and exits the process with a status computed from the response status code. The mapping of response status code to exit status is as follows:
401: 1 402 to 500 (other than 403 and 404): 2 403: 3 404: 4 500+: 5
func SetContextRequestID ¶ added in v1.2.0
SetContextRequestID sets a request ID in the given context and returns a new context.
Types ¶
type APIKeySigner ¶
type APIKeySigner struct {
// SignQuery indicates whether to set the API key in the URL query with key KeyName
// or whether to use a header with name KeyName.
SignQuery bool
// KeyName is the name of the HTTP header or query string that contains the API key.
KeyName string
// KeyValue stores the actual key.
KeyValue string
// Format is the format used to render the key, e.g. "Bearer %s"
Format string
}
APIKeySigner implements API Key auth.
type BasicSigner ¶
type BasicSigner struct {
// Username is the basic auth user.
Username string
// Password is err guess what? the basic auth password.
Password string
}
BasicSigner implements basic auth.
type Client ¶
type Client struct {
// Doer is the underlying http client.
Doer
// Scheme overrides the default action scheme.
Scheme string
// Host is the service hostname.
Host string
// UserAgent is the user agent set in requests made by the client.
UserAgent string
// Dump indicates whether to dump request response.
Dump bool
}
Client is the common client data structure for all goa service clients.
type Doer ¶
Doer defines the Do method of the http client.
func HTTPClientDoer ¶
HTTPClientDoer turns a stdlib http.Client into a Doer. Use it to enable to call New() with an http.Client.
type JWTSigner ¶
type JWTSigner struct {
// TokenSource is a JWT token source.
// See https://godoc.org/golang.org/x/oauth2/jwt#Config.TokenSource for an example
// of an implementation.
TokenSource TokenSource
}
JWTSigner implements JSON Web Token auth.
type OAuth2Signer ¶
type OAuth2Signer struct {
// TokenSource is an OAuth2 access token source.
// See package golang/oauth2 and its subpackage for implementations of token
// sources.
TokenSource TokenSource
}
OAuth2Signer adds a authorization header to the request using the given OAuth2 token source to produce the header value.
type StaticToken ¶
type StaticToken struct {
// Value used to set the auth header.
Value string
// OAuth type, defaults to "Bearer".
Type string
}
StaticToken implements a token that sets the auth header with a given static value.
func (*StaticToken) SetAuthHeader ¶
func (t *StaticToken) SetAuthHeader(r *http.Request)
SetAuthHeader sets the Authorization header to r.
func (*StaticToken) Valid ¶
func (t *StaticToken) Valid() bool
Valid reports whether Token can be used to properly sign requests.
type StaticTokenSource ¶
type StaticTokenSource struct {
StaticToken *StaticToken
}
StaticTokenSource implements a token source that always returns the same token.
func (*StaticTokenSource) Token ¶
func (s *StaticTokenSource) Token() (Token, error)
Token returns the static token.
type Token ¶
type Token interface {
// SetAuthHeader sets the Authorization header to r.
SetAuthHeader(r *http.Request)
// Valid reports whether Token can be used to properly sign requests.
Valid() bool
}
Token is the interface to an OAuth2 token implementation. It can be implemented with https://godoc.org/golang.org/x/oauth2#Token.
type TokenSource ¶
type TokenSource interface {
// Token returns a token or an error.
// Token must be safe for concurrent use by multiple goroutines.
// The returned Token must not be modified.
Token() (Token, error)
}
A TokenSource is anything that can return a token.