Documentation ¶
Overview ¶
Package macaron is a high productive and modular web framework in Go.
Index ¶
- Constants
- Variables
- func Bind(req *http.Request, v any) error
- func MatchTest(pattern, url string) bool
- func Params(r *http.Request) map[string]string
- func RemoteAddr(req *http.Request) string
- func SetURLParams(r *http.Request, vars map[string]string) *http.Request
- func Version() string
- type BeforeFunc
- type BeforeHandler
- type Context
- func (ctx *Context) GetCookie(name string) string
- func (ctx *Context) HTML(status int, name string, data any)
- func (ctx *Context) JSON(status int, data any)
- func (ctx *Context) Query(name string) string
- func (ctx *Context) QueryBool(name string) bool
- func (ctx *Context) QueryFloat64(name string) float64
- func (ctx *Context) QueryInt(name string) int
- func (ctx *Context) QueryInt64(name string) int64
- func (ctx *Context) QueryInt64WithDefault(name string, d int64) int64
- func (ctx *Context) QueryStrings(name string) []string
- func (ctx *Context) Redirect(location string, status ...int)
- func (ctx *Context) RemoteAddr() string
- type Handle
- type Handler
- type Leaf
- type Macaron
- type Middleware
- type Mux
- type ResponseWriter
- type Router
- func (r *Router) Any(pattern string, h ...Handler)
- func (r *Router) Delete(pattern string, h ...Handler)
- func (r *Router) Get(pattern string, h ...Handler)
- func (r *Router) Group(pattern string, fn func(), h ...Handler)
- func (r *Router) Handle(method string, pattern string, handlers []Handler)
- func (r *Router) Head(pattern string, h ...Handler)
- func (r *Router) NotFound(handlers ...Handler)
- func (r *Router) Options(pattern string, h ...Handler)
- func (r *Router) Patch(pattern string, h ...Handler)
- func (r *Router) Post(pattern string, h ...Handler)
- func (r *Router) Put(pattern string, h ...Handler)
- func (r *Router) ServeHTTP(rw http.ResponseWriter, req *http.Request)
- type Tree
- type Validator
Constants ¶
const ( DEV = "development" PROD = "production" )
const StatusHijacked = -1
Variables ¶
var ( // Env is the environment that Macaron is executing in. // The MACARON_ENV is read on initialization to set this variable. Env = DEV )
var MaxMemory = int64(1024 * 1024 * 10)
MaxMemory is the maximum amount of memory to use when parsing a multipart form. Set this to whatever value you prefer; default is 10 MB.
Functions ¶
func RemoteAddr ¶
func SetURLParams ¶
SetURLParams sets the named URL parameters for the given request. This should only be used for testing purposes.
Types ¶
type BeforeFunc ¶
type BeforeFunc func(ResponseWriter)
BeforeFunc is a function that is called before the ResponseWriter has been written to.
type BeforeHandler ¶
type BeforeHandler func(rw http.ResponseWriter, req *http.Request) bool
BeforeHandler represents a handler executes at beginning of every request. Macaron stops future process when it returns true.
type Context ¶
type Context struct { Req *http.Request Resp ResponseWriter // contains filtered or unexported fields }
Context represents the runtime context of current request of Macaron instance. It is the integration of most frequently used middlewares and helper methods.
func FromContext ¶
FromContext returns the macaron context stored in a context.Context, if any.
func (*Context) QueryFloat64 ¶
QueryFloat64 returns query result in float64 type.
func (*Context) QueryInt64 ¶
QueryInt64 returns query result in int64 type.
func (*Context) QueryInt64WithDefault ¶
func (*Context) QueryStrings ¶
QueryStrings returns a list of results by given query name.
func (*Context) RemoteAddr ¶
RemoteAddr returns more real IP address.
type Handle ¶
Handle is a function that can be registered to a route to handle HTTP requests. Like http.HandlerFunc, but has a third parameter for the values of wildcards (variables).
type Handler ¶
type Handler any
Handler can be any callable function. Macaron attempts to inject services into the handler's argument list, and panics if an argument could not be fulfilled via dependency injection.
type Leaf ¶
type Leaf struct {
// contains filtered or unexported fields
}
Leaf represents a leaf route information.
type Macaron ¶
type Macaron struct { *Router // contains filtered or unexported fields }
Macaron represents the top level web application. Injector methods can be invoked to map services on a global level.
func New ¶
func New() *Macaron
New creates a bare bones Macaron instance. Use this method if you want to have full control over the middleware that is used.
func (*Macaron) ServeHTTP ¶
func (m *Macaron) ServeHTTP(rw http.ResponseWriter, req *http.Request)
ServeHTTP is the HTTP Entry point for a Macaron instance. Useful if you want to control your own HTTP server. Be aware that none of middleware will run without registering any router.
func (*Macaron) SetURLPrefix ¶
SetURLPrefix sets URL prefix of router layer, so that it support suburl.
func (*Macaron) Use ¶
Use registers the provided Handler as a middleware. The argument may be any supported handler or the Middleware type Deprecated: use UseMiddleware instead
func (*Macaron) UseMiddleware ¶
func (m *Macaron) UseMiddleware(mw Middleware)
UseMiddleware registers the given Middleware
type Middleware ¶
func Renderer ¶
func Renderer(dir, leftDelim, rightDelim string) Middleware
Renderer is a Middleware that injects a template renderer into the macaron context, enabling ctx.HTML calls in the handlers. If MACARON_ENV is set to "development" then templates will be recompiled on every request. For more performance, set the MACARON_ENV environment variable to "production".
type ResponseWriter ¶
type ResponseWriter interface { http.ResponseWriter http.Flusher // Status returns the status code of the response or 0 if the response has not been written. Status() int // Written returns whether or not the ResponseWriter has been written. Written() bool // Size returns the size of the response body. Size() int // Before allows for a function to be called before the ResponseWriter has been written to. This is // useful for setting headers or any other operations that must happen before a response has been written. Before(BeforeFunc) // Needed to support https://pkg.go.dev/k8s.io/apiserver@v0.27.2/pkg/endpoints/responsewriter#WrapForHTTP1Or2 http.CloseNotifier Unwrap() http.ResponseWriter }
ResponseWriter is a wrapper around http.ResponseWriter that provides extra information about the response. It is recommended that middleware handlers use this construct to wrap a responsewriter if the functionality calls for it.
func NewResponseWriter ¶
func NewResponseWriter(method string, rw http.ResponseWriter) ResponseWriter
NewResponseWriter creates a ResponseWriter that wraps an http.ResponseWriter
func Rw ¶
func Rw(rw http.ResponseWriter, req *http.Request) ResponseWriter
Rw returns a ResponseWriter. If the argument already satisfies the interface, it is returned as is, otherwise it is wrapped using NewResponseWriter
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router represents a Macaron router layer.
func (*Router) Handle ¶
Handle registers a new request handle with the given pattern, method and handlers.
func (*Router) NotFound ¶
NotFound configurates http.HandlerFunc which is called when no matching route is found. If it is not set, http.NotFound is used. Be sure to set 404 response code in your handler.
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree represents a router tree in Macaron.