Documentation
¶
Index ¶
- Variables
- type Config
- type Cookie
- type Ctx
- func (c *Ctx) Bind(v interface{}) error
- func (c *Ctx) ClientAddress() string
- func (c *Ctx) ContentType() string
- func (c *Ctx) Cookie(name string) string
- func (c *Ctx) Cookies() []*Cookie
- func (c *Ctx) DelHeader(name string)
- func (c *Ctx) GetContentType() string
- func (c *Ctx) GetCookie(name string) *Cookie
- func (c *Ctx) GetHeader(name string) string
- func (c *Ctx) Header(name string) string
- func (c *Ctx) Headers() http.Header
- func (c *Ctx) Param(name string) *RequestParam
- func (c *Ctx) Params() []*RequestParam
- func (c *Ctx) Push(target string, headers map[string]string) error
- func (c *Ctx) Query(name string) string
- func (c *Ctx) QueryParams() netURL.Values
- func (c *Ctx) QueryString() string
- func (c *Ctx) Redirect(url string) error
- func (c *Ctx) RemoteAddress() string
- func (c *Ctx) SetContentType(ct string)
- func (c *Ctx) SetCookie(name string, cookie *Cookie)
- func (c *Ctx) SetHeader(name string, value string)
- func (c *Ctx) SetHeaderValue(name string, values ...string)
- func (c *Ctx) SetHeaderValues(name string, values []string)
- func (c *Ctx) SetRawHeader(name string, values []string)
- func (c *Ctx) SetStatus(code int)
- func (c *Ctx) Write(content io.ReadSeeker) error
- func (c *Ctx) WriteBlob(b []byte) error
- func (c *Ctx) WriteFile(filename string) error
- func (c *Ctx) WriteHTML(h string) error
- func (c *Ctx) WriteJSON(v interface{}) error
- func (c *Ctx) WriteMsgpack(v interface{}) error
- func (c *Ctx) WriteProtobuf(v interface{}) error
- func (c *Ctx) WriteString(s string) error
- func (c *Ctx) WriteTOML(v interface{}) error
- func (c *Ctx) WriteXML(v interface{}) error
- type Err
- type Handler
- type Instance
- func (in *Instance) AddHTTPWare(wares ...func(http.Handler) http.Handler)
- func (in *Instance) AddPreHTTPWare(wares ...func(http.Handler) http.Handler)
- func (in *Instance) AddPreWare(wares ...Middleware)
- func (in *Instance) AddWare(wares ...Middleware)
- func (in *Instance) CONNECT(path string, h Handler, wares ...Middleware)
- func (in *Instance) DELETE(path string, h Handler, wares ...Middleware)
- func (in *Instance) FILE(path, filename string, wares ...Middleware)
- func (in *Instance) GET(path string, h Handler, wares ...Middleware)
- func (in *Instance) HEAD(path string, h Handler, wares ...Middleware)
- func (in *Instance) OPTIONS(path string, h Handler, wares ...Middleware)
- func (in *Instance) PATCH(path string, h Handler, wares ...Middleware)
- func (in *Instance) POST(path string, h Handler, wares ...Middleware)
- func (in *Instance) PUT(path string, h Handler, wares ...Middleware)
- func (in *Instance) Run() error
- func (in *Instance) STATIC(prefix, root string, wares ...Middleware)
- func (in *Instance) ServeHTTP(rw http.ResponseWriter, r *http.Request)
- func (in *Instance) Stop() error
- func (in *Instance) TRACE(path string, h Handler, wares ...Middleware)
- func (in *Instance) TimelyStop(when time.Duration, postStop func())
- type Middleware
- type Node
- type NodeKind
- type RequestParam
- type RequestParamFileValue
- type RequestParamValue
- func (rpv *RequestParamValue) Bool() (bool, error)
- func (rpv *RequestParamValue) File() (*RequestParamFileValue, error)
- func (rpv *RequestParamValue) Float32() (float32, error)
- func (rpv *RequestParamValue) Float64() (float64, error)
- func (rpv *RequestParamValue) Int() (int, error)
- func (rpv *RequestParamValue) Int8() (int8, error)
- func (rpv *RequestParamValue) Int16() (int16, error)
- func (rpv *RequestParamValue) Int32() (int32, error)
- func (rpv *RequestParamValue) Int64() (int64, error)
- func (rpv *RequestParamValue) String() string
- func (rpv *RequestParamValue) Uint() (uint, error)
- func (rpv *RequestParamValue) Uint8() (uint8, error)
- func (rpv *RequestParamValue) Uint16() (uint16, error)
- func (rpv *RequestParamValue) Uint32() (uint32, error)
- func (rpv *RequestParamValue) Uint64() (uint64, error)
- type Router
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is the standard 404 error ErrNotFound = MakeErr(404, "not found") // ErrMethodNotAllowed is the standard 405 error ErrMethodNotAllowed = MakeErr(405, "method not allowed") // ErrIndeterminateData for when reflection goes wrong or there is malformed data ErrIndeterminateData = MakeErr(400, "unparsible or malformed data") // ErrUnsupportedMediaType for when a media type cannot be handled ErrUnsupportedMediaType = MakeErr(415, "unsupported media type") // ErrRequestBodyEmpty request's body content is absent; malformed POST most likely. ErrRequestBodyEmpty = MakeErr(400, "request body empty, cannot proceed") // ErrBadRange is for when the Requested Range is Not Satisfiable (out of bounds or such) ErrBadRange = MakeErr(416, "unsatisfiable range") // ErrPreConditionFail a precondition for request completion has not been met ErrPreConditionFail = MakeErr(412, "precondition failed") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
AppName string `json:"appname,omitempty" toml:"appname,omitempty"`
Domain string `json:"domain,omitempty" toml:"domain,omitempty"`
MaintainerEmail string `json:"maintainer_email,omitempty" toml:"maintainer_email,omitempty"`
DevMode bool `json:"devmode,omitempty" toml:"devmode,omitempty"`
Address string `json:"address" toml:"address"`
SecondaryServerAddress string `json:"secondary_server_address" toml:"secondary_server_address"`
DevAddress string `json:"dev_address,omitempty" toml:"dev_address,omitempty"`
DevSecondaryServerAddress string `json:"dev_secondary_server_address,omitempty" toml:"dev_secondary_server_address,omitempty"`
PreferMsgpack bool `json:"prefer_msgpack,omitempty" toml:"prefer_msgpack,omitempty"`
AutoPush bool `json:"autopush,omitempty" toml:"autopush,omitempty"`
AutoCert bool `json:"autocert,omitempty" toml:"autocert,omitempty"`
DevAutoCert bool `json:"dev_autocert,omitempty" toml:"dev_autocert,omitempty"`
Whitelist []string `json:"whitelist,omitempty" toml:"whitelist,omitempty"`
TLSKey string `json:"tls_key,omitempty" toml:"tls_key,omitempty"`
TLSCert string `json:"tls_cert,omitempty" toml:"tls_cert,omitempty"`
Assets string `json:"assets,omitempty" toml:"assets,omitempty"`
Private string `json:"private,omitempty" toml:"private,omitempty"`
Cache string `json:"cache,omitempty" toml:"cache,omitempty"`
Raw map[string]interface{} `json:"-" toml:"-"`
}
Config holds all the information necessary to fire up a mak instance
type Ctx ¶
type Ctx struct {
R *http.Request
W http.ResponseWriter
Body io.Writer
ContentLength int64
Written bool
Status int
Path string
// contains filtered or unexported fields
}
Ctx handler context
func (*Ctx) Bind ¶
Bind interprets/parses/unmarshalls either the Request body (POST) or other Params (GET).
func (*Ctx) ClientAddress ¶
ClientAddress returns the original network address that sent the r.
func (*Ctx) ContentType ¶
ContentType returns the value of the Content-Type header
func (*Ctx) GetContentType ¶
GetContentType returns the value of the Content-Type header
func (*Ctx) GetCookie ¶
GetCookie returns an *http.Cookie matching a name and nil if no such cookie exists
func (*Ctx) GetHeader ¶
GetHeader reads a header off what's already set in (http.ResponseWriter).Header()
func (*Ctx) Param ¶
func (c *Ctx) Param(name string) *RequestParam
Param returns the matched `RequestParam` for the name. It returns nil if not found.
func (*Ctx) Params ¶
func (c *Ctx) Params() []*RequestParam
Params returns all the `RequestParam` in the c.
func (*Ctx) Push ¶
Push initiates an HTTP/2 server push. This constructs a synthetic request using the target and headers, serializes that request into a PUSH_PROMISE frame, then dispatches that request using the server's request handlec. The target must either be an absolute path (like "/path") or an absolute URL that contains a valid host and the same scheme as the parent request. If the target is a path, it will inherit the scheme and host of the parent request. The headers specifies additional promised request headers. The headers cannot include HTTP/2 pseudo headers like ":path" and ":scheme", which will be added automatically.
func (*Ctx) QueryParams ¶
QueryParams returns the query parameters as `url.Values`.
func (*Ctx) QueryString ¶
QueryString returns the raw URL query string.
func (*Ctx) RemoteAddress ¶
RemoteAddress returns the last network address that sent the r.
func (*Ctx) SetContentType ¶
SetContentType sets the http response's Content-Type header
func (*Ctx) SetHeaderValue ¶
SetHeaderValue sets a header's value(s)
func (*Ctx) SetHeaderValues ¶
SetHeaderValues sets a header's values
func (*Ctx) SetRawHeader ¶
SetRawHeader sets a header
func (*Ctx) Write ¶
func (c *Ctx) Write(content io.ReadSeeker) error
Write responds to the client with the content.
func (*Ctx) WriteMsgpack ¶
WriteMsgpack responds to the client with the "application/msgpack" content v.
func (*Ctx) WriteProtobuf ¶
WriteProtobuf responds to the client with the "application/protobuf" content v.
func (*Ctx) WriteString ¶
WriteString responds to the client with the "text/plain" content s.
type Err ¶
Err is mak's standard error type
type Instance ¶
type Instance struct {
Server *http.Server
SecondaryServer *http.Server
Config *Config
RawConfig map[string]interface{}
Router *Router
Middleware []Middleware
PreMiddleware []Middleware
AssetWares []Middleware
SecondaryServerHandler http.Handler
AutoCert *autocert.Manager
ErrorHandler func(*Ctx, error) error
NotFoundHandler func(*Ctx) error
}
Instance is a mak server with all the trinkets and bells
func MakeFromConf ¶
MakeFromConf read's a config file for configuration instructions instead of the usual user/manually generated *Config
func (*Instance) AddHTTPWare ¶
AddHTTPWare adds plain http middleware(s) to the instance
func (*Instance) AddPreHTTPWare ¶
AddPreHTTPWare adds plain http middleware(s) to the instance
func (*Instance) AddPreWare ¶
func (in *Instance) AddPreWare(wares ...Middleware)
AddPreWare adds middleware(s) to the instance, wares that run before all the others
func (*Instance) AddWare ¶
func (in *Instance) AddWare(wares ...Middleware)
AddWare adds middleware(s) to the instance
func (*Instance) CONNECT ¶
func (in *Instance) CONNECT(path string, h Handler, wares ...Middleware)
CONNECT registers a new CONNECT route for the path with the matching h in the router with the optional route-level gases.
func (*Instance) DELETE ¶
func (in *Instance) DELETE(path string, h Handler, wares ...Middleware)
DELETE registers a new DELETE route for the path with the matching h in the router with the optional route-level gases.
func (*Instance) FILE ¶
func (in *Instance) FILE(path, filename string, wares ...Middleware)
FILE registers a new route with the path to serve a static file with the filename and the optional route-level gases.
func (*Instance) GET ¶
func (in *Instance) GET(path string, h Handler, wares ...Middleware)
GET registers a new GET route for the path with the matching h in the router with the optional route-level gases.
func (*Instance) HEAD ¶
func (in *Instance) HEAD(path string, h Handler, wares ...Middleware)
HEAD registers a new HEAD route for the path with the matching h in the router with the optional route-level gases.
func (*Instance) OPTIONS ¶
func (in *Instance) OPTIONS(path string, h Handler, wares ...Middleware)
OPTIONS registers a new OPTIONS route for the path with the matching h in the router with the optional route-level gases.
func (*Instance) PATCH ¶
func (in *Instance) PATCH(path string, h Handler, wares ...Middleware)
PATCH registers a new PATCH route for the path with the matching h in the router with the optional route-level gases.
func (*Instance) POST ¶
func (in *Instance) POST(path string, h Handler, wares ...Middleware)
POST registers a new POST route for the path with the matching h in the router with the optional route-level gases.
func (*Instance) PUT ¶
func (in *Instance) PUT(path string, h Handler, wares ...Middleware)
PUT registers a new PUT route for the path with the matching h in the router with the optional route-level gases.
func (*Instance) Run ¶
Run let's the mak instance's purpose actuate, until it dies or is otherwise stopped
func (*Instance) STATIC ¶
func (in *Instance) STATIC(prefix, root string, wares ...Middleware)
STATIC registers a new route with the path prefix to serve the static files from the root with the optional route-level gases.
func (*Instance) ServeHTTP ¶
func (in *Instance) ServeHTTP(rw http.ResponseWriter, r *http.Request)
ServeHTTP implements the `http.Handler`.
func (*Instance) TRACE ¶
func (in *Instance) TRACE(path string, h Handler, wares ...Middleware)
TRACE registers a new TRACE route for the path with the matching h in the router with the optional route-level gases.
func (*Instance) TimelyStop ¶
TimelyStop makes the mak instance run no longer, when specified
type Middleware ¶
Middleware defines a function to process gases.
func WrapHTTPMiddleware ¶
func WrapHTTPMiddleware(m func(http.Handler) http.Handler) Middleware
WrapHTTPMiddleware is a convenience method allowing the use of conventional `http.Handler` middleware by wrapping it and internally converting the middleware into a `Gas`.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node is the Node of the radix tree.
type RequestParam ¶
type RequestParam struct {
Name string
Values []*RequestParamValue
}
RequestParam is an HTTP request param.
func (*RequestParam) Value ¶
func (rp *RequestParam) Value() *RequestParamValue
Value returns the first value of the rp. It returns nil if the rp is nil or there are no values.
type RequestParamFileValue ¶
type RequestParamFileValue struct {
Filename string
ContentLength int64
// contains filtered or unexported fields
}
RequestParamFileValue is an HTTP request param file value.
type RequestParamValue ¶
type RequestParamValue struct {
// contains filtered or unexported fields
}
RequestParamValue is an HTTP request param value.
func (*RequestParamValue) Bool ¶
func (rpv *RequestParamValue) Bool() (bool, error)
Bool returns a `bool` from the rpv's underlying value.
func (*RequestParamValue) File ¶
func (rpv *RequestParamValue) File() (*RequestParamFileValue, error)
File returns a `RequestParamFileValue` from the rpv's underlying value.
func (*RequestParamValue) Float32 ¶
func (rpv *RequestParamValue) Float32() (float32, error)
Float32 returns a `float32` from the rpv's underlying value.
func (*RequestParamValue) Float64 ¶
func (rpv *RequestParamValue) Float64() (float64, error)
Float64 returns a `float64` from the rpv's underlying value.
func (*RequestParamValue) Int ¶
func (rpv *RequestParamValue) Int() (int, error)
Int returns an `int` from the rpv's underlying value.
func (*RequestParamValue) Int8 ¶
func (rpv *RequestParamValue) Int8() (int8, error)
Int8 returns an `int8` from the rpv's underlying value.
func (*RequestParamValue) Int16 ¶
func (rpv *RequestParamValue) Int16() (int16, error)
Int16 returns an `int16` from the rpv's underlying value.
func (*RequestParamValue) Int32 ¶
func (rpv *RequestParamValue) Int32() (int32, error)
Int32 returns an `int32` from the rpv's underlying value.
func (*RequestParamValue) Int64 ¶
func (rpv *RequestParamValue) Int64() (int64, error)
Int64 returns an `int64` from the rpv's underlying value.
func (*RequestParamValue) String ¶
func (rpv *RequestParamValue) String() string
String returns a `string` from the rpv's underlying value.
func (*RequestParamValue) Uint ¶
func (rpv *RequestParamValue) Uint() (uint, error)
Uint returns an `uint` from the rpv's underlying value.
func (*RequestParamValue) Uint8 ¶
func (rpv *RequestParamValue) Uint8() (uint8, error)
Uint8 returns an `uint8` from the rpv's underlying value.
func (*RequestParamValue) Uint16 ¶
func (rpv *RequestParamValue) Uint16() (uint16, error)
Uint16 returns an `uint16` from the rpv's underlying value.
func (*RequestParamValue) Uint32 ¶
func (rpv *RequestParamValue) Uint32() (uint32, error)
Uint32 returns an `uint32` from the rpv's underlying value.
func (*RequestParamValue) Uint64 ¶
func (rpv *RequestParamValue) Uint64() (uint64, error)
Uint64 returns an `uint64` from the rpv's underlying value.
type Router ¶
Router is a registry of all Registered routes.