github.com/goadesign/goa/client


client

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

Overview

Index

Package files

cli.go client.go signers.go

func ContextRequestID

func ContextRequestID(ctx context.Context) string

ContextRequestID extracts the Request ID from the context.

func ContextWithRequestID

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

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

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

func WSRead(ws *websocket.Conn)

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

func WSWrite

func WSWrite(ws *websocket.Conn)

WSWrite sends STDIN lines to a websocket server.

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.

func (*APIKeySigner) Sign

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

Sign adds the API key header to the request.

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.

func (*BasicSigner) Sign

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

Sign adds the basic auth header to the request.

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.

func New

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

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

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

Doer defines the Do method of the http client.

func HTTPClientDoer

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

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

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

Sign adds the JWT auth header.

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.

func (*OAuth2Signer) Sign

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

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

type Signer

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

Signer is the common interface implemented by all signers.

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.


Generated by godoc2md