Documentation ¶
Index ¶
- Constants
- Variables
- func NewClient(address string, opts ...ClientOpt) cmds.Executor
- func NewHandler(env cmds.Environment, root *cmds.Command, cfg *ServerConfig) http.Handler
- type ClientOpt
- type Response
- type ResponseEmitter
- type ResponseEmitterOption
- type ServerConfig
- func (cfg *ServerConfig) AddAllowedHeaders(headers ...string)
- func (cfg *ServerConfig) AllowedMethods() []string
- func (cfg *ServerConfig) AllowedOrigins() []string
- func (cfg *ServerConfig) AppendAllowedOrigins(origins ...string)
- func (cfg *ServerConfig) SetAllowCredentials(flag bool)
- func (cfg *ServerConfig) SetAllowedMethods(methods ...string)
- func (cfg *ServerConfig) SetAllowedOrigins(origins ...string)
Constants ¶
const ( ACAOrigin = "Access-Control-Allow-Origin" ACAMethods = "Access-Control-Allow-Methods" ACACredentials = "Access-Control-Allow-Credentials" )
const (
ApiUrlFormat = "%s%s/%s?%s"
)
const (
// StreamErrHeader is used as trailer when stream errors happen.
StreamErrHeader = "X-Stream-Error"
)
Variables ¶
var ( // AllowedExposedHeadersArr defines the default Access-Control-Expose-Headers. AllowedExposedHeadersArr = []string{streamHeader, channelHeader, extraContentLengthHeader} // AllowedExposedHeaders is the list of defaults Access-Control-Expose-Headers separated by comma. AllowedExposedHeaders = strings.Join(AllowedExposedHeadersArr, ", ") )
var ( // ErrNotFound is returned when the endpoint does not exist. ErrNotFound = errors.New("404 page not found") )
var ( MIMEEncodings = map[string]cmds.EncodingType{ "application/json": cmds.JSON, "application/xml": cmds.XML, "text/plain": cmds.Text, } )
var OptionSkipMap = map[string]bool{ "api": true, }
Functions ¶
func NewHandler ¶
func NewHandler(env cmds.Environment, root *cmds.Command, cfg *ServerConfig) http.Handler
NewHandler creates the http.Handler for the given commands.
Types ¶
type ClientOpt ¶
type ClientOpt func(*client)
ClientOpt is an option that can be passed to the HTTP client constructor.
func ClientWithAPIPrefix ¶
ClientWithAPIPrefix specifies an API URL prefix.
func ClientWithFallback ¶
ClientWithFallback adds a fallback executor to the client.
Note: This may run the PreRun function twice.
func ClientWithHTTPClient ¶
ClientWithHTTPClient specifies a custom http.Client. Defaults to http.DefaultClient.
func ClientWithHeader ¶
ClientWithHeader adds an HTTP header to the client.
func ClientWithUserAgent ¶
ClientWithUserAgent specifies the HTTP user agent for the client.
type ResponseEmitter ¶
type ResponseEmitter interface { cmds.ResponseEmitter http.Flusher }
ResponseEmitter interface defines the components that can care of sending the response to HTTP Requests.
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)
NewResponseEmitter 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 // AllowGet indicates whether or not this server accepts GET requests. // When unset, the server only accepts POST, HEAD, and OPTIONS. // // This is different from CORS AllowedMethods. The API may allow GET // requests in general, but reject them in CORS. That will allow // websites to include resources from the API but not _read_ them. AllowGet bool // contains filtered or unexported fields }
func NewServerConfig ¶
func NewServerConfig() *ServerConfig
func (*ServerConfig) AddAllowedHeaders ¶
func (cfg *ServerConfig) AddAllowedHeaders(headers ...string)
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)