http

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2020 License: MIT Imports: 21 Imported by: 37

Documentation

Index

Constants

View Source
const (
	ACAOrigin      = "Access-Control-Allow-Origin"
	ACAMethods     = "Access-Control-Allow-Methods"
	ACACredentials = "Access-Control-Allow-Credentials"
)
View Source
const (
	ApiUrlFormat = "%s%s/%s?%s"
)
View Source
const (
	StreamErrHeader = "X-Stream-Error"
)

Variables

View Source
var (
	HeadRequest = fmt.Errorf("HEAD request")

	AllowedExposedHeadersArr = []string{streamHeader, channelHeader, extraContentLengthHeader}
	AllowedExposedHeaders    = strings.Join(AllowedExposedHeadersArr, ", ")
)
View Source
var (
	ErrNotFound = errors.New("404 page not found")
)
View Source
var (
	MIMEEncodings = map[string]cmds.EncodingType{
		"application/json": cmds.JSON,
		"application/xml":  cmds.XML,
		"text/plain":       cmds.Text,
	}
)
View Source
var OptionSkipMap = map[string]bool{
	"api": true,
}

Functions

func NewClient

func NewClient(address string, opts ...ClientOpt) cmds.Executor

NewClient constructs a new HTTP-backed command executor.

func NewHandler

func NewHandler(env cmds.Environment, root *cmds.Command, cfg *ServerConfig) http.Handler

Types

type ClientOpt

type ClientOpt func(*client)

ClientOpt is an option that can be passed to the HTTP client constructor.

func ClientWithAPIPrefix

func ClientWithAPIPrefix(apiPrefix string) ClientOpt

ClientWithAPIPrefix specifies an API URL prefix.

func ClientWithFallback added in v0.1.0

func ClientWithFallback(exe cmds.Executor) ClientOpt

ClientWithFallback adds a fallback executor to the client.

Note: This may run the PreRun function twice.

func ClientWithHTTPClient added in v0.1.1

func ClientWithHTTPClient(hc *http.Client) ClientOpt

ClientWithHTTPClient specifies a custom http.Client. Defaults to http.DefaultClient.

func ClientWithUserAgent

func ClientWithUserAgent(ua string) ClientOpt

ClientWithUserAgent specifies the HTTP user agent for the client.

type Response

type Response struct {
	// contains filtered or unexported fields
}

func (*Response) Error

func (res *Response) Error() *cmds.Error

func (*Response) Length

func (res *Response) Length() uint64

func (*Response) Next

func (res *Response) Next() (interface{}, error)

func (*Response) Request

func (res *Response) Request() *cmds.Request

type ResponseEmitter

type ResponseEmitter interface {
	cmds.ResponseEmitter
	http.Flusher
}

func NewFlushForwarder

func NewFlushForwarder(r cmds.ResponseEmitter, f http.Flusher) ResponseEmitter

func NewResponseEmitter

func NewResponseEmitter(w http.ResponseWriter, method string, req *cmds.Request, opts ...ResponseEmitterOption) (ResponseEmitter, error)

NewResponeEmitter returns a new ResponseEmitter.

type ResponseEmitterOption

type ResponseEmitterOption func(*responseEmitter)

ResponseEmitterOption is the type describing options to the NewResponseEmitter function.

type ServerConfig

type ServerConfig struct {
	// APIPath is the prefix of all request paths.
	// Example: host:port/api/v0/add. Here the APIPath is /api/v0
	APIPath string

	// Headers is an optional map of headers that is written out.
	Headers map[string][]string
	// contains filtered or unexported fields
}

func NewServerConfig

func NewServerConfig() *ServerConfig

func (*ServerConfig) AllowedMethods

func (cfg *ServerConfig) AllowedMethods() []string

func (*ServerConfig) AllowedOrigins

func (cfg *ServerConfig) AllowedOrigins() []string

func (*ServerConfig) AppendAllowedOrigins

func (cfg *ServerConfig) AppendAllowedOrigins(origins ...string)

func (*ServerConfig) SetAllowCredentials

func (cfg *ServerConfig) SetAllowCredentials(flag bool)

func (*ServerConfig) SetAllowedMethods

func (cfg *ServerConfig) SetAllowedMethods(methods ...string)

func (*ServerConfig) SetAllowedOrigins

func (cfg *ServerConfig) SetAllowedOrigins(origins ...string)

Jump to

Keyboard shortcuts

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