Documentation
¶
Index ¶
- Constants
- Variables
- func CleanPath(p string) string
- func MethodColor(method string) (color string)
- func PanicHandle(c context.Context)
- func SignalQueue(e *Engine)
- func StatusColor(code int) (color string)
- type Conf
- type Ctx
- func (c *Ctx) Abort(code int)
- func (c *Ctx) Data() map[string]interface{}
- func (c *Ctx) Error(err error, meta interface{})
- func (c *Ctx) Fail(code int, err error)
- func (c *Ctx) Files() map[string][]*multipart.FileHeader
- func (r Ctx) Fmt() string
- func (c *Ctx) Form() url.Values
- func (c *Ctx) LastError() error
- func (r Ctx) Latency() time.Duration
- func (r Ctx) LogFmt() string
- func (r Ctx) PostProcess(req *http.Request, rw ResponseWriter)
- func (c *Ctx) Request() *http.Request
- func (r Ctx) Requester(req *http.Request)
- func (r Ctx) Start()
- func (c *Ctx) Status(code int)
- func (c *Ctx) StatusFunc() (func(int), bool)
- func (r Ctx) Stop()
- func (c *Ctx) Writer() ResponseWriter
- type Engine
- func (e *Engine) Emit(message string)
- func (e *Engine) Handler(method, path string, handler http.Handler)
- func (e *Engine) HandlerFunc(method, path string, handler http.HandlerFunc)
- func (e *Engine) Lookup(method, path string) (Manage, Params, bool)
- func (e *Engine) Manage(method string, path string, m Manage)
- func (e *Engine) Message(message string)
- func (e *Engine) PanicMessage(message string)
- func (e *Engine) Reconfigure(reconfigure func() error) error
- func (engine *Engine) Run(addr string)
- func (e *Engine) Send(queue string, message string)
- func (e *Engine) ServeFiles(path string, root http.FileSystem)
- func (engine *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (e *Engine) SetConf(opts ...Conf) error
- func (e *Engine) SetConfBool(fieldname string, as bool) error
- func (e *Engine) SetConfInt64(fieldname string, as int64) error
- type EngineError
- type Group
- type HttpStatus
- type HttpStatuses
- type Manage
- type Param
- type Params
- type ResponseWriter
- type Signal
- type Signals
Constants ¶
const ( ErrorTypeInternal = 1 << iota ErrorTypeExternal = 1 << iota ErrorTypePanic = 1 << iota ErrorTypeAll = 0xffffffff )
const (
NotWritten = -1
)
Variables ¶
var (
CurrentContext context.Context
)
var (
EnginePanic = []byte("engine-panic")
)
Functions ¶
func CleanPath ¶
CleanPath is the URL version of path.Clean, it returns a canonical URL path for p, eliminating . and .. elements.
The following rules are applied iteratively until no further processing can be done:
- Replace multiple slashes with a single slash.
- Eliminate each . path name element (the current directory).
- Eliminate each inner .. path name element (the parent directory) along with the non-.. element that precedes it.
- Eliminate .. elements that begin a rooted path: that is, replace "/.." by "/" at the beginning of a path.
If the result of this process is an empty string, "/" is returned
func MethodColor ¶
func PanicHandle ¶
PanicHandle is the default Manage for 500 & internal panics. Retrieves all ErrorTypePanic from context.Context.Errors, sends signal, logs to stdout or logger, and serves a basic html page if engine.ServePanic is true.
func SignalQueue ¶
func SignalQueue(e *Engine)
A simple Signal queue outputting everything emitted to engine.Signals.
func StatusColor ¶
Types ¶
type Conf ¶
A configuration function that takes an engine pointer, configures the engine within the function, and returns an error.
func HTMLStatus ¶
func Logger ¶
Logger specifies a log.Logger, and sets LoggingOn to true, and capturing signals with Head labeled "do-log"
func MaxFormMemory ¶
func RedirectFixedPath ¶
func RedirectTrailingSlash ¶
func ServePanic ¶
type Ctx ¶
type Ctx struct { RW ResponseWriter Params Params Errors errorMsgs // contains filtered or unexported fields }
Ctx is the core request-response context passed between any Manage handlers, useful for storing & persisting data within a request & response.
func (*Ctx) Error ¶
Attaches an error to a list of errors. Call Error for each error that occurred during the resolution of a request.
func (*Ctx) Fail ¶
Fail is the same as Abort plus an error message. Calling `c.Fail(500, err)` is equivalent to: ``` c.Error(err, "Failed.") c.Abort(500) ```
func (Ctx) PostProcess ¶
func (r Ctx) PostProcess(req *http.Request, rw ResponseWriter)
func (*Ctx) Status ¶
Calls an HttpStatus in the current group by integer code from the Context, if the status exists.
func (*Ctx) StatusFunc ¶
func (*Ctx) Writer ¶
func (c *Ctx) Writer() ResponseWriter
type Engine ¶
type Engine struct { *Group Logger *log.Logger Signals Signals Queues queues // contains filtered or unexported fields }
Engine is the the core struct with groups, routing, signaling and more.
func New ¶
New produces a new engine, with default configuration, a base group, method for retrieving a new Ctx, and signalling.
func (*Engine) HandlerFunc ¶
func (e *Engine) HandlerFunc(method, path string, handler http.HandlerFunc)
HandlerFunc allows the use of a http.HandlerFunc as request manage.
func (*Engine) PanicMessage ¶
PanicMessage goes to a standard and unavaoidable log, then emits a signal.
func (*Engine) Reconfigure ¶
func (*Engine) ServeFiles ¶
func (e *Engine) ServeFiles(path string, root http.FileSystem)
ServeFiles serves files from the given file system root. The path must end with "/*filepath", files are then served from the local path /defined/root/dir/*filepath.
e.g., if root is "/etc" and *filepath is "passwd", the local file "/etc/passwd" would be served.
Internally a http.FileServer is used, therefore http.NotFound is used instead of the Router's NotFound handler.
To use the operating system's file system implementation, use http.Dir:
router.ServeFiles("/src/*filepath", http.Dir("/var/www"))
type EngineError ¶
type EngineError struct {
// contains filtered or unexported fields
}
func (*EngineError) Error ¶
func (e *EngineError) Error() string
type Group ¶
type Group struct { HttpStatuses // contains filtered or unexported fields }
func (*Group) Middleware ¶
func (group *Group) Middleware(h ...http.HandlerFunc)
func (*Group) New ¶
New creates a group from an existing group using the the groups prefix and the provided component string as a prefix. The existing group will be the parent of the new group.
type HttpStatus ¶
Status code, message, and Manage handlers for a http status.
func NewHttpStatus ¶
func NewHttpStatus(code int, message string) *HttpStatus
Create new HttpStatus with the code, message, and default Manage handlers.
func (*HttpStatus) Update ¶
func (h *HttpStatus) Update(handlers ...Manage)
Adds any number of custom Manage to the HttpStatus, between the default status before & after manage.
type HttpStatuses ¶
type HttpStatuses map[int]*HttpStatus
A map of HttpStatus instances, keyed by status code
func (HttpStatuses) New ¶
func (hs HttpStatuses) New(h *HttpStatus)
New adds a new HttpStatus to HttpStatuses keyed by status code.
type Manage ¶
Manage is a function that can be registered to a route to handle HTTP requests. Like http.HandlerFunc, but takes a context.Context
type Params ¶
type Params []Param
Params is a Param-slice, as returned by the router. The slice is ordered, the first URL parameter is also the first slice value. It is safe to read values by the index.