http

package
v0.0.0-...-46249b4 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2018 License: MIT Imports: 23 Imported by: 0

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 (
	ErrAPINotRunning = errors.New("api not running")
)
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 NewHandler

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

Types

type Client

type Client interface {
	Send(req *cmds.Request) (cmds.Response, error)
}

Client is the commands HTTP client interface.

func NewClient

func NewClient(address string, opts ...ClientOpt) Client

type ClientOpt

type ClientOpt func(*client)

func ClientWithAPIPrefix

func ClientWithAPIPrefix(apiPrefix string) ClientOpt

func ClientWithUserAgent

func ClientWithUserAgent(ua string) ClientOpt

type Response

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

func (*Response) Error

func (res *Response) Error() *cmdkit.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) ResponseEmitter

NewResponeEmitter returns a new ResponseEmitter.

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