Documentation
¶
Index ¶
- Constants
- Variables
- func NewHandler(ctx cmds.Context, root *cmds.Command, cfg *ServerConfig) http.Handler
- func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error)
- type Client
- type Handler
- type MultiFileReader
- type Response
- type ResponseEmitter
- type ServerConfig
- 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 ¶
View Source
const ( ApiUrlFormat = "http://%s%s/%s?%s" ApiPath = "/api/v0" // TODO: make configurable )
View Source
const ( ACAOrigin = "Access-Control-Allow-Origin" ACAMethods = "Access-Control-Allow-Methods" ACACredentials = "Access-Control-Allow-Credentials" )
View Source
const (
StreamErrHeader = "X-Stream-Error"
)
Variables ¶
View Source
var AllowedExposedHeaders = strings.Join(AllowedExposedHeadersArr, ", ")
View Source
var AllowedExposedHeadersArr = []string{streamHeader, channelHeader, extraContentLengthHeader}
View Source
var (
ErrNotFound = errors.New("404 page not found")
)
View Source
var (
HeadRequest = fmt.Errorf("HEAD request")
)
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(ctx cmds.Context, root *cmds.Command, cfg *ServerConfig) http.Handler
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
The Handler struct is funny because we want to wrap our internal handler with CORS while keeping our fields.
type MultiFileReader ¶
MultiFileReader reads from a `commands.File` (which can be a directory of files or a regular file) as HTTP multipart encoded data.
func NewMultiFileReader ¶
func NewMultiFileReader(file files.File, form bool) *MultiFileReader
NewMultiFileReader constructs a MultiFileReader. `file` can be any `commands.File`. If `form` is set to true, the multipart data will have a Content-Type of 'multipart/form-data', if `form` is false, the Content-Type will be 'multipart/mixed'.
func (*MultiFileReader) Boundary ¶
func (mfr *MultiFileReader) Boundary() string
Boundary returns the boundary string to be used to separate files in the multipart data
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 {
// 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)
Click to show internal directories.
Click to hide internal directories.