goa: github.com/goadesign/goa/client Index | Files

package client

import "github.com/goadesign/goa/client"

Index

Package Files

cli.go client.go signers.go

func ContextRequestID Uses

func ContextRequestID(ctx context.Context) string

ContextRequestID extracts the Request ID from the context.

func ContextWithRequestID Uses

func ContextWithRequestID(ctx context.Context) (context.Context, string)

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 Uses

func HandleResponse(c *Client, resp *http.Response, pretty bool)

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 Uses

func SetContextRequestID(ctx context.Context, reqID string) context.Context

SetContextRequestID sets a request ID in the given context and returns a new context.

func WSRead Uses

func WSRead(ws *websocket.Conn)

WSRead reads from a websocket and print the read messages to STDOUT.

func WSWrite Uses

func WSWrite(ws *websocket.Conn)

WSWrite sends STDIN lines to a websocket server.

type APIKeySigner Uses

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.

func (*APIKeySigner) Sign Uses

func (s *APIKeySigner) Sign(req *http.Request) error

Sign adds the API key header to the request.

type BasicSigner Uses

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.

func (*BasicSigner) Sign Uses

func (s *BasicSigner) Sign(req *http.Request) error

Sign adds the basic auth header to the request.

type Client Uses

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.

func New Uses

func New(c Doer) *Client

New creates a new API client that wraps c. If c is nil, the returned client wraps http.DefaultClient.

func (*Client) Do Uses

func (c *Client) Do(ctx context.Context, req *http.Request) (*http.Response, error)

Do wraps the underlying http client Do method and adds logging. The logger should be in the context.

type Doer Uses

type Doer interface {
    Do(context.Context, *http.Request) (*http.Response, error)
}

Doer defines the Do method of the http client.

func HTTPClientDoer Uses

func HTTPClientDoer(hc *http.Client) Doer

HTTPClientDoer turns a stdlib http.Client into a Doer. Use it to enable to call New() with an http.Client.

type JWTSigner Uses

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.

func (*JWTSigner) Sign Uses

func (s *JWTSigner) Sign(req *http.Request) error

Sign adds the JWT auth header.

type OAuth2Signer Uses

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.

func (*OAuth2Signer) Sign Uses

func (s *OAuth2Signer) Sign(req *http.Request) error

Sign refreshes the access token if needed and adds the OAuth header.

type Signer Uses

type Signer interface {
    // Sign adds required headers, cookies etc.
    Sign(*http.Request) error
}

Signer is the common interface implemented by all signers.

type StaticToken Uses

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 Uses

func (t *StaticToken) SetAuthHeader(r *http.Request)

SetAuthHeader sets the Authorization header to r.

func (*StaticToken) Valid Uses

func (t *StaticToken) Valid() bool

Valid reports whether Token can be used to properly sign requests.

type StaticTokenSource Uses

type StaticTokenSource struct {
    StaticToken *StaticToken
}

StaticTokenSource implements a token source that always returns the same token.

func (*StaticTokenSource) Token Uses

func (s *StaticTokenSource) Token() (Token, error)

Token returns the static token.

type Token Uses

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 Uses

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.

Package client imports 16 packages (graph) and is imported by 55 packages. Updated 2017-04-13. Refresh now. Tools for package owners.