rest

package
v0.10.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2019 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package rest implements a REST client for communicating with remote services.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Name added in v0.10.1

func Name(s string) func(*Client)

Name returns an option that overrides the service name on the client.

Types

type Client

type Client struct {
	Client http.Client
	// contains filtered or unexported fields
}

Client implements an HTTP/REST client for communicating with remote services.

func New

func New(config []byte, opts ...func(*Client)) (Client, error)

New returns a new Client for config.

func (Client) Do

func (c Client) Do(ctx context.Context, method, path string) (*http.Response, error)

Do executes a request using the client.

func (Client) Service

func (c Client) Service() string

Service returns the name of the service this Client is configured for.

func (Client) WithBytes

func (c Client) WithBytes(body []byte) Client

WithBytes returns a shallow copy of the client with the bytes set as the message body to include in the requests.

func (Client) WithHeader

func (c Client) WithHeader(k, v string) Client

WithHeader returns a shallow copy of the client with a header to include the requests.

func (Client) WithJSON

func (c Client) WithJSON(body interface{}) Client

WithJSON returns a shallow copy of the client with the JSON value set as the message body to include the requests. This function sets the Content-Type header.

type Config

type Config struct {
	Name           string            `json:"name"`
	URL            string            `json:"url"`
	Headers        map[string]string `json:"headers"`
	AllowInsureTLS bool              `json:"allow_insecure_tls,omitempty"`
	Credentials    struct {
		Bearer *struct {
			Scheme string `json:"scheme,omitempty"`
			Token  string `json:"token"`
		} `json:"bearer,omitempty"`
		ClientTLS *struct {
			Cert                 string `json:"cert"`
			PrivateKey           string `json:"private_key"`
			PrivateKeyPassphrase string `json:"private_key_passphrase,omitempty"`
		} `json:"client_tls,omitempty"`
	} `json:"credentials"`
}

Config represents configuration for a REST client.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL