request

package
v2.15.5+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2017 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Overview

Package request of Tideland GoREST provides a simple way to handle cross-server requests in the Tideland REST ecosystem.

Index

Constants

View Source
const (
	ErrNoServerDefined = iota + 1
	ErrCannotPrepareRequest
	ErrHTTPRequestFailed
	ErrProcessingRequestContent
	ErrInvalidContent
	ErrAnalyzingResponse
	ErrDecodingResponse
	ErrInvalidContentType
)

Error codes of the request package.

Variables

This section is empty.

Functions

func NewContext

func NewContext(ctx context.Context, servers Servers) context.Context

NewContext returns a new context that carries configured servers.

func Version

func Version() version.Version

Version returns the version of the REST package.

Types

type Caller

type Caller interface {
	// Get performs a GET request on the defined resource.
	Get(resource, resourceID string, params *Parameters) (Response, error)

	// Head performs a HEAD request on the defined resource.
	Head(resource, resourceID string, params *Parameters) (Response, error)

	// Put performs a PUT request on the defined resource.
	Put(resource, resourceID string, params *Parameters) (Response, error)

	// Post performs a POST request on the defined resource.
	Post(resource, resourceID string, params *Parameters) (Response, error)

	// Patch performs a PATCH request on the defined resource.
	Patch(resource, resourceID string, params *Parameters) (Response, error)

	// Delete performs a DELETE request on the defined resource.
	Delete(resource, resourceID string, params *Parameters) (Response, error)

	// Options performs a OPTIONS request on the defined resource.
	Options(resource, resourceID string, params *Parameters) (Response, error)
}

Caller provides an interface to make calls to configured services.

type KeyValues

type KeyValues map[string]string

KeyValues handles keys and values for request headers and cookies.

type Parameters

type Parameters struct {
	Version     version.Version
	Token       jwt.JWT
	ContentType string
	Content     interface{}
	Accept      string
}

Parameters allows to pass parameters to a call.

type Response

type Response interface {
	// StatusCode returns the HTTP status code of the response.
	StatusCode() int

	// Header returns the HTTP header of the response.
	Header() http.Header

	// HasContentType checks the content type regardless of charsets.
	HasContentType(contentType string) bool

	// Read decodes the content into the passed data depending
	// on the content type.
	Read(data interface{}) error

	// ReadFeedback tries to unmarshal the content of the
	// response into a rest package feedback.
	ReadFeedback() (rest.Feedback, bool)
}

Response wraps all infos of a test response.

type Servers

type Servers interface {
	// Add adds a domain server configuration.
	Add(domain string, url string, transport *http.Transport)

	// Caller retrieves a caller for a domain.
	Caller(domain string) (Caller, error)
}

Servers maps IDs of domains to their server configurations. Multiple ones can be added per domain for spreading the load or provide higher availability.

func FromContext

func FromContext(ctx context.Context) (Servers, bool)

FromContext returns the servers configuration stored in ctx, if any.

func NewServers

func NewServers() Servers

NewServers creates a new servers manager.

Jump to

Keyboard shortcuts

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