Documentation ¶
Index ¶
- func NewTree() *tree
- func ToMap(tre *tree) map[string]Handler
- type ChainHandler
- type Group
- func (g *Group) Delete(path string, handler Handler) *Group
- func (g *Group) Get(path string, handler Handler) *Group
- func (g *Group) GetGroupRoutes() []*cacheRoute
- func (g *Group) Head(path string, handler Handler) *Group
- func (g *Group) Options(path string, handler Handler) *Group
- func (g *Group) Patch(path string, handler Handler)
- func (g *Group) Post(path string, handler Handler) *Group
- func (g *Group) Put(path string, handler Handler) *Group
- type Handler
- type Middlewares
- type Minima
- func (m *Minima) Delete(path string, handler Handler) *Minima
- func (m *Minima) File(pth string, dir string)
- func (m *Minima) Get(path string, handler Handler) *Minima
- func (m *Minima) GetProp(key string) interface{}
- func (m *Minima) Head(path string, handler Handler) *Minima
- func (m *Minima) Listen(addr string) error
- func (m *Minima) NotFound(handler Handler) *Minima
- func (m *Minima) Options(path string, handler Handler) *Minima
- func (m *Minima) Patch(path string, handler Handler) *Minima
- func (m *Minima) Post(path string, handler Handler) *Minima
- func (m *Minima) Put(path string, handler Handler) *Minima
- func (m *Minima) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (m *Minima) SetProp(key string, value interface{}) *Minima
- func (m *Minima) Shutdown(ctx context.Context) error
- func (m *Minima) ShutdownTimeout(t time.Duration) *Minima
- func (m *Minima) Static(pth string, dir string)
- func (m *Minima) Use(handler Handler) *Minima
- func (m *Minima) UseGroup(grp *Group) *Minima
- func (m *Minima) UseRaw(handler ...func(http.Handler) http.Handler) *Minima
- func (m *Minima) UseRouter(router *Router) *Minima
- type Node
- type OutgoingHeader
- func (h *OutgoingHeader) BaseHeaders()
- func (h *OutgoingHeader) Clone() http.Header
- func (h *OutgoingHeader) Del(key string) *OutgoingHeader
- func (h *OutgoingHeader) Flush() bool
- func (h *OutgoingHeader) Get(key string) string
- func (h *OutgoingHeader) Set(key string, value string) *OutgoingHeader
- func (h *OutgoingHeader) Setlength(len string) *OutgoingHeader
- func (h *OutgoingHeader) Status(code int) *OutgoingHeader
- type Request
- func (r *Request) Body() map[string][]string
- func (r *Request) BodyValue(key string) []string
- func (r *Request) CloneHeader() http.Header
- func (r *Request) Cookies() []*http.Cookie
- func (r *Request) DelHeader(key string)
- func (r *Request) FormFile(key string) (*multipart.FileHeader, error)
- func (r *Request) FormParams() (url.Values, error)
- func (r *Request) FormValue(key string) string
- func (r *Request) GetCookie(key string) *http.Cookie
- func (r *Request) GetHeader(key string) string
- func (r *Request) IP() string
- func (r *Request) IsSocket() bool
- func (r *Request) IsTLS() bool
- func (r *Request) Json() *json.Decoder
- func (r *Request) Method() string
- func (r *Request) MultipartForm() (*multipart.Form, error)
- func (r *Request) Param(key string) string
- func (r *Request) Path() string
- func (r *Request) Query(key string) string
- func (r *Request) QueryParams() url.Values
- func (r *Request) QueryString() string
- func (r *Request) Raw() *http.Request
- func (r *Request) SchemeType() string
- func (r *Request) SetHeader(key string, value string) *Request
- func (r *Request) SetParam(key string, value string) *Request
- type Response
- func (res *Response) BadGateway() *Response
- func (res *Response) BadRequest() *Response
- func (res *Response) ClearCookie(cookie *http.Cookie) *Response
- func (res *Response) CloneHeaders() http.Header
- func (res *Response) CloseConn() error
- func (res *Response) DelHeader(key string) *Response
- func (res *Response) Error(status int, err string) *Response
- func (res *Response) File(dir string) error
- func (res *Response) FlushHeaders() *Response
- func (res *Response) Forbidden() *Response
- func (res *Response) GetHeader(key string) string
- func (res *Response) InternalServerError() *Response
- func (res *Response) JSON(content interface{}) *Response
- func (res *Response) MovedPermanently() *Response
- func (res *Response) NoContent(code int) error
- func (res *Response) NotFound() *Response
- func (res *Response) OK() *Response
- func (res *Response) Raw() http.ResponseWriter
- func (res *Response) Redirect(url string) *Response
- func (res *Response) Render(path string, data interface{}) *Response
- func (res *Response) Send(content string) *Response
- func (res *Response) ServiceUnavailable() *Response
- func (res *Response) SetBaseHeaders() *Response
- func (res *Response) SetCookie(cookie *http.Cookie) *Response
- func (res *Response) SetHeader(key string, value string) *Response
- func (res *Response) Setlength(len string) *Response
- func (res *Response) Status(status int) *Response
- func (res *Response) Stream(contentType string, read io.Reader) error
- func (res *Response) TemporaryRedirect() *Response
- func (res *Response) Unauthorized() *Response
- func (res *Response) WriteBytes(bytes []byte) error
- func (res *Response) XML(content interface{}, indent string) error
- type Router
- func (r *Router) Delete(path string, handler Handler) *Router
- func (r *Router) Get(path string, handler Handler) *Router
- func (r *Router) GetCacheRoutes() []*cacheRoute
- func (r *Router) Head(path string, handler Handler) *Router
- func (r *Router) NotFound(handler Handler) *Router
- func (r *Router) Options(path string, handler Handler) *Router
- func (r *Router) Patch(path string, handler Handler)
- func (r *Router) Post(path string, handler Handler) *Router
- func (r *Router) Put(path string, handler Handler) *Router
- func (r *Router) Register(method string, path string, handler Handler) error
- func (r *Router) UseRouter(Router *Router)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ChainHandler ¶
type ChainHandler struct { Endpoint http.Handler Middlewares Middlewares // contains filtered or unexported fields }
*
- @info Create a middleware chain
- @property {http.Handler} [Endpoint] The endpoint of the chain stack
- @property {http.Handler} [chain] The actual middleware stack chain
- @property {Middlewares} Middlewares The middleware stack
func (*ChainHandler) ServeHTTP ¶
func (c *ChainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
*
- @info Injects the middleware chain to minima instance
- @param {http.ResponseWriter} [w] The net/http response instance
- @param {http.Request} [r] The net/http request instance
type Group ¶ added in v1.1.3
type Group struct {
// contains filtered or unexported fields
}
*
- @info The minima group structure
- @property {[]cacheroute} [route] The array of cached routes
- @property {[string} [prefix] The group prefix
func (*Group) Delete ¶ added in v1.1.3
*
- @info Adds route with Delete method
- @param {string} path The route path
- @param {...Handler} [handler] The handler for the given route
- @returns {*Group}
func (*Group) Get ¶ added in v1.1.3
*
- @info Adds route with Get method
- @param {string} path The route path
- @param {...Handler} [handler] The handler for the given route
- @returns {*Router}
func (*Group) GetGroupRoutes ¶ added in v1.1.3
func (g *Group) GetGroupRoutes() []*cacheRoute
*
- @info Returns all routes for the group
- @return {[]cachRoute}
func (*Group) Head ¶ added in v1.1.3
*
- @info Adds route with Head method
- @param {string} path The route path
- @param {...Handler} [handler] The handler for the given route
- @returns {*Group}
func (*Group) Options ¶ added in v1.1.3
*
- @info Adds route with Options method
- @param {string} path The route path
- @param {...Handler} [handler] The handler for the given route
- @returns {*Group}
func (*Group) Patch ¶ added in v1.1.3
*
- @info Adds route with Patch method
- @param {string} path The route path
- @param {...Handler} [handler] The handler for the given route
- @returns {*Group}
type Middlewares ¶
func Chain ¶
func Chain(middlewares ...func(http.Handler) http.Handler) Middlewares
* n* @info Create a middleware chain
func (Middlewares) Handler ¶
func (mws Middlewares) Handler(h http.Handler) http.Handler
*
- @info Creates a new chain handler instance
- @param {http.Handler} [h] The handler stack to append
- @returns {http.Handler}
func (Middlewares) HandlerFunc ¶
func (mws Middlewares) HandlerFunc(h http.HandlerFunc) http.Handler
*
- @info Creates a new chain handler instance from handlerfunc
- @param {http.HandlerFunc} [h] The handlerfunc stack to append
- @returns {http.Handler}
type Minima ¶
*
- @info The framework structure
- @property {*http.Server} [server] The net/http stock server
- @property {bool} [started] Whether the server has started or not
- @property {*time.Duration} [Timeout] The router's breathing time
- @property {*Router} [router] The core router instance running with the server
- @property {map[string]interface{}} [properties] The properties for the server instance
- @property {*Config} [Config] The core config file for middlewares and router instances
- @property {*time.Duration} [drain] The router's drain time
func New ¶
func New() *Minima
*
- @info Make a new default minima instance
- @example `
func main() { app := minima.New() app.Get("/", func(res *minima.Response, req *minima.Request) { res.Status(200).Send("Hello World") }) app.Listen(":3000") }
`
- @returns {minima}
func (*Minima) Delete ¶
*
- @info Adds route with Delete method
- @param {string} path The route path
- @param {...Handler} [handler] The handler for the given route
- @returns {*minima}
func (*Minima) File ¶ added in v1.1.4
*
- @info Injects a static file to minima instance
- @param {string} [pth] The route path for static serve
- @param {string} [dir] The dir of the file
- @returns {}
func (*Minima) Get ¶
*
- @info Adds route with Get method
- @param {string} path The route path
- @param {...Handler} [handler] The handler for the given route
- @returns {*minima}
func (*Minima) GetProp ¶
*
- @info Gets prop from core properties
- @param {string} [key] Key for the prop
- @returns {interface{}}
func (*Minima) Head ¶
*
- @info Adds route with Head method
- @param {string} path The route path
- @param {...Handler} [handler] The handler for the given route
- @returns {*minima}
func (*Minima) Listen ¶
*
- @info Starts the actual http server
- @param {string} [addr] The port for the server instance to run on
- @returns {error}
func (*Minima) NotFound ¶
*
- @info Injects the NotFound handler to the minima instance
- @param {Handler} [handler] Minima handler instance
- @returns {*minima}
func (*Minima) Options ¶
*
- @info Adds route with Options method
- @param {string} path The route path
- @param {...Handler} [handler] The handler for the given route
- @returns {*minima}
func (*Minima) Patch ¶
*
- @info Adds route with Patch method
- @param {string} path The route path
- @param {...Handler} [handler] The handler for the given route
- @returns {*minima}
func (*Minima) Post ¶
*
- @info Adds route with Post method
- @param {string} path The route path
- @param {...Handler} [handler] The handler for the given route
- @returns {*minima}
func (*Minima) Put ¶
*
- @info Adds route with Put method
- @param {string} path The route path
- @param {...Handler} [handler] The handler for the given route
- @returns {*minima}
func (*Minima) ServeHTTP ¶
func (m *Minima) ServeHTTP(w http.ResponseWriter, r *http.Request)
*
- @info Injects the actual minima server logic to http
- @param {http.ResponseWriter} [w] The net/http response instance
- @param {http.Request} [r] The net/http request instance
- @returns {}
func (*Minima) SetProp ¶
*
- @info Declares prop for core properties
- @param {string} [key] Key for the prop
- @param {interface{}} [value] Value of the prop
- @returns {*minima}
func (*Minima) Shutdown ¶
*
- @info Shutdowns the core instance
- @param {context.Context} [ctx] The context for shutdown
- @returns {error}
func (*Minima) ShutdownTimeout ¶
*
- @info The drain timeout for the core instance
- @param {time.Duration} time The time period for drain
- @returns {*minima}
func (*Minima) Static ¶ added in v1.1.4
*
- @info Injects a static directory to minima instance
- @param {string} [pth] The route path for static serve
- @param {string} [dir] The dir of the static folder
- @returns {}
func (*Minima) Use ¶
*
- @info Injects minima middleware to the stack
- @param {Handler} [handler] The handler stack to append
- @returns {}
func (*Minima) UseGroup ¶ added in v1.1.3
*
- @info Injects minima group to main router stack
- @param {Group} [grp] The minima group to append
- @returns {}
type Node ¶ added in v1.1.0
type Node struct {
// contains filtered or unexported fields
}
*
- @info The tree Node structure
- @property {Handler} [handler] The handler to be used
- @property {[]*edge} [edges] The array of node edges
- @property {int} [priority] The priority of the node in the tree
- @property {int} [depth] The depth of the node in the tree
type OutgoingHeader ¶
type OutgoingHeader struct {
// contains filtered or unexported fields
}
*
- @info The Outgoing header structure
- @property {http.Request} [req] The net/http request instance
- @property {http.ResponseWriter} [res] The net/http response instance
- @property {bool} [body] Whether body has been sent or not
- @property {int} [status] response status code
func NewResHeader ¶
func NewResHeader(res http.ResponseWriter, req *http.Request) *OutgoingHeader
*
- @info Make a new default request header instance
- @param {http.Request} [req] The net/http request instance
- @param {http.ResponseWriter} [res] The net/http response instance
- @returns {OutgoingHeader}
func (*OutgoingHeader) BaseHeaders ¶
func (h *OutgoingHeader) BaseHeaders()
*
- @info Sends good stack of base headers
- @returns {}
func (*OutgoingHeader) Clone ¶
func (h *OutgoingHeader) Clone() http.Header
*
- @info Clones all headers from response
- @returns {OutgoingHeader}
func (*OutgoingHeader) Del ¶
func (h *OutgoingHeader) Del(key string) *OutgoingHeader
*
- @info Deletes header from respose
- @param {string} [key] Key of the header
- @returns {OutgoingHeader}
func (*OutgoingHeader) Flush ¶
func (h *OutgoingHeader) Flush() bool
*
- @info Flushes and writes header to route
- @returns {bool}
func (*OutgoingHeader) Get ¶
func (h *OutgoingHeader) Get(key string) string
*
- @info Gets the header from response headers
- @param {string} [key] Key of the header
- @returns {string}
func (*OutgoingHeader) Set ¶
func (h *OutgoingHeader) Set(key string, value string) *OutgoingHeader
*
- @info Sets and new header to response
- @param {string} [key] Key of the new header
- @param {string} [value] Value of the new header
- @returns {OutgoingHeader}
func (*OutgoingHeader) Setlength ¶
func (h *OutgoingHeader) Setlength(len string) *OutgoingHeader
*
- @info Sets content lenght
- @param {string} [len] The lenght of the content
- @returns {OutgoingHeader}
func (*OutgoingHeader) Status ¶
func (h *OutgoingHeader) Status(code int) *OutgoingHeader
*
- @info Sets response status
- @param {int} [code] The status code for the response
- @returns {OutgoingHeader}
type Request ¶
*
- @info The request structure
- @property {*http.Request} [ref] The net/http request instance
- @property {multipart.Reader} [fileReader] file reader instance
- @property {map[string][]string} [body] Value of the request body
- @property {string} [method] Request method
- @property {[]*Params} [Params] Request path parameters
- @property {query} url.Values Request path query params
- @property {json.Decoder} json Json decoder instance
func (*Request) BodyValue ¶ added in v1.1.1
*
- @info Gets specified request body
- @param {string} [key] Key of the request body
- @returns {[]string}
func (*Request) CloneHeader ¶ added in v1.1.5
*
- @info Clones all headers from request body
- @returns {http.Header}
func (*Request) DelHeader ¶ added in v1.1.5
*
- @info Deletes a paticular Header by its key
- @param {string} [key] key of the Header
func (*Request) FormFile ¶ added in v1.1.1
func (r *Request) FormFile(key string) (*multipart.FileHeader, error)
*
- @info Gets a file from request form
- @returns {multipart.FileHeader, error}
func (*Request) FormParams ¶ added in v1.1.1
*
- @info Gets all the form param values
- @returns {url.Values, error}
func (*Request) FormValue ¶ added in v1.1.1
*
- @info Gets the values from request form
- @param {string} [key] The key of the value
- @returns {string}
func (*Request) GetCookie ¶
*
- @info Get a paticular cookie by its key
- @param {string} [key] key of the cookie
- @returns {*http.Cookie}
func (*Request) GetHeader ¶
*
- @info Get a paticular Header by its key
- @param {string} [key] key of the Header
- @returns {string}
func (*Request) IsSocket ¶ added in v1.1.1
*
- @info Whether the request is a websocket or not
- @returns {bool}
func (*Request) MultipartForm ¶ added in v1.1.1
*
- @info Gets a Multi part form from request form
- @returns {multipart.Form, error}
func (*Request) Param ¶ added in v1.1.1
*
- @info Gets param from route path
- @param {string} [key] Key of the route param
- @returns {string}
func (*Request) Query ¶ added in v1.0.1
*
- @info Gets request path query
- @param {string} [key] key of the request query
- @returns {string}
func (*Request) QueryParams ¶ added in v1.1.1
*
- @info Gets request path query in an array
- @param {string} [key] key of the request query
- @returns {string}
func (*Request) QueryString ¶ added in v1.1.1
*
- @info Gets request path query in a string
- @returns {string}
func (*Request) SchemeType ¶ added in v1.1.1
*
- @info Gets the scheme type of the request body
- @returns {bool}
type Response ¶
type Response struct { HasEnded bool // contains filtered or unexported fields }
*
- @info The response instance structure
- @property {http.ResponseWriter} [ref] The net/http response instance
- @property {string} url The route url
- @property {string} [method] The route http method
- @property {OutgoingHeader} [header] The response header instance
- @property {string} [host] The minima host
- @property {bool} [HasEnded] Whether the response has ended
func (*Response) ClearCookie ¶
*
- @info Clear a cookie
- @param {*http.Cookie} [cookie]
- @returns {Response}
func (*Response) CloneHeaders ¶
*
- @info Clones all header from response
- @param {} []
- @returns {http.Header}
func (*Response) DelHeader ¶
*
- @info Deletes header from response
- @param {string} [key] Key of the header
- @returns {string}
func (*Response) Error ¶
*
- @info Returns error to the route
- @param {int} [status] The status code of the error
- @param {string} [err] The error to write
- @returns {Response}
func (*Response) GetHeader ¶
*
- @info Gets header from response
- @param {string} [key] Key of the header
- @returns {string}
func (*Response) JSON ¶ added in v1.1.1
*
- @info Writes json content to the route
- @param {interface{}} [content] The json struct to write to the page
- @returns {Response}
func (*Response) NoContent ¶ added in v1.1.1
*
- @info Sets page's content to none
- @param {int} [code] The status code
- @returns {error}
func (*Response) Raw ¶
func (res *Response) Raw() http.ResponseWriter
*
- @info Returns raw http.ResponseWriter instance
- @returns {http.ResponseWriter}
func (*Response) Redirect ¶
*
- @info Redirects to a different route
- @param {string} url The url of the route to redirect
- @returns {Response}
func (*Response) Render ¶
*
- @info Renders a html page with payload data to the route
- @param {string} path The dir path of the html page
- @param {interface{}} [data] The payload data to pass in html page
- @returns {Response}
func (*Response) Send ¶
*
- @info Sends string to the route
- @param {string} [content] The content to write
- @returns {Response}
func (*Response) ServiceUnavailable ¶ added in v1.0.2
*
- @info Set status code as 503
- @returns {Response}
func (*Response) SetBaseHeaders ¶
*
- @info Sets a good stack of base headers for response
- @returns {*Response}
func (*Response) SetCookie ¶
*
- @info Set a cookie
- @param {*http.Cookie} [cookie]
- @returns {Response}
func (*Response) SetHeader ¶
*
- @info Sets headers for response
- @param {string} [key] Key of the header
- @param {string} [value] Value of the header
- @returns {string}
func (*Response) Setlength ¶
*
- @info Sets length of the response body
- @param {string} [len] length value of the header
- @returns {*Response}
func (*Response) Status ¶
*
- @info Sets response status
- @param {int} [status] The status code for the response
- @returns {Response}
func (*Response) Stream ¶ added in v1.1.1
*
- @info Streams content to the route
- @param {string} [contentType] The content type to stream
- @param {io.Reader} [read] The io.Reader instance
- @returns {error}
func (*Response) WriteBytes ¶
*
- @info Writes bytes to the route
- @param {[]bytes} bytes The bytes to write
- @returns {Response}
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
*
- @info The router structure
- @property {map[string][]*tree} [routes] The radix-tree based routes
- @property {Handler} [notfound] The handler for the non matching routes
- @property {[]Handler} [minmiddleware] The minima handler middleware stack
- @property {[]func(http.Handler)http.Handler} [middleware] The http.Handler middleware stack
- @property {bool} [isCache] Whether the router is cache or not
- @property {[]*cacheRoute} [cacheRoute] Slice of cached routes
- @property {http.Handler} [handler] The single http.Handler built on chaining the whole middleware stack
func (*Router) Delete ¶
*
- @info Adds route with Delete method
- @param {string} path The route path
- @param {...Handler} [handler] The handler for the given route
- @returns {*Router}
func (*Router) Get ¶
*
- @info Adds route with Get method
- @param {string} path The route path
- @param {...Handler} [handler] The handler for the given route
- @returns {*Router}
func (*Router) GetCacheRoutes ¶ added in v1.1.2
func (r *Router) GetCacheRoutes() []*cacheRoute
*
- @info Returns all the routes in router
- @returns {map[string][]*mux}
func (*Router) Head ¶
*
- @info Adds route with Head method
- @param {string} path The route path
- @param {...Handler} [handler] The handler for the given route
- @returns {*Router}
func (*Router) Options ¶
*
- @info Adds route with Options method
- @param {string} path The route path
- @param {...Handler} [handler] The handler for the given route
- @returns {*Router}
func (*Router) Patch ¶
*
- @info Adds route with Patch method
- @param {string} path The route path
- @param {...Handler} [handler] The handler for the given route
- @returns {*Router}
func (*Router) Post ¶
*
- @info Adds route with Post method
- @param {string} path The route path
- @param {...Handler} [handler] The handler for the given route
- @returns {*Router}
func (*Router) Put ¶
*
- @info Adds route with Put method
- @param {string} path The route path
- @param {...Handler} [handler] The handler for the given route
- @returns {*Router}
Source Files ¶
Click to show internal directories.
Click to hide internal directories.