Documentation ¶
Index ¶
- Constants
- Variables
- func NewHandler(env cmds.Environment, root *cmds.Command, cfg *ServerConfig) http.Handler
- type Client
- type ClientOpt
- type Response
- type ResponseEmitter
- type ResponseEmitterOption
- 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 ( 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 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)
Click to show internal directories.
Click to hide internal directories.