Documentation ¶
Index ¶
- type Cherry
- func (c *Cherry) BindContext(ctx context.Context)
- func (c *Cherry) Delete(route string, h Handler)
- func (c *Cherry) Get(route string, h Handler)
- func (c *Cherry) Group(prefix string) *Group
- func (c *Cherry) Handle(method, path string, h http.Handler)
- func (c *Cherry) Head(route string, h Handler)
- func (c *Cherry) Options(route string, h Handler)
- func (c *Cherry) Post(route string, h Handler)
- func (c *Cherry) Put(route string, h Handler)
- func (c *Cherry) Serve(port int) error
- func (c *Cherry) ServeCustom(s *http.Server) error
- func (c *Cherry) ServeCustomTLS(s *http.Server, certFile, keyFile string) error
- func (c *Cherry) ServeHTTP(rw http.ResponseWriter, r *http.Request)
- func (c *Cherry) ServeTLS(port int, certFile, keyFile string) error
- func (c *Cherry) SetErrorHandler(h ErrorHandlerFunc)
- func (c *Cherry) SetMethodNotAllowed(h http.Handler)
- func (c *Cherry) SetNotFound(h http.Handler)
- func (c *Cherry) Static(prefix, dir string)
- func (c *Cherry) Use(handlers ...Handler)
- type Context
- func (c *Context) DecodeJSON(v interface{}) error
- func (c *Context) Form(name string) string
- func (c *Context) Header(name string) string
- func (c *Context) JSON(code int, v interface{}) error
- func (c *Context) Param(name string) string
- func (c *Context) Query(name string) string
- func (c *Context) Redirect(url string, code int) error
- func (c *Context) Request() *http.Request
- func (c *Context) Response() http.ResponseWriter
- func (c *Context) Text(code int, text string) error
- type ErrorHandlerFunc
- type Group
- type Handler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cherry ¶
type Cherry struct { ErrorHandler ErrorHandlerFunc // Output writes the access-log and debug parameters for web-server Output io.Writer // HasAccessLog enables access-log for cherry. The default is false HasAccessLog bool // HTTP2 enables the HTTP2 protocol on the server(TLS) HTTP2 bool // contains filtered or unexported fields }
Cherry is a web framework for making fast and simple web applications in the Go programming language. Cherry supports by one of the fastest request router in Golang. It is also provides a graceful web server that can serve TLS encrypted requests as well.
func (*Cherry) BindContext ¶
BindContext lets you provide a context that will live a full http roundtrip BindContext is mostly used in a func main() to provide init variables that may be created only once, like a database connection. If BindContext is not called, Cherry will use a context.Background().
func (*Cherry) Group ¶
Group returns a new Group that will inherit all of its parents middleware. you can reset the middleware registered to the group by calling Reset().
func (*Cherry) Handle ¶
Handle adapts the usage of an http.Handler and will be invoked when the router matches the prefix and request method.
func (*Cherry) ServeCustom ¶
ServeCustom method serves the application with custom server configuration.
func (*Cherry) ServeCustomTLS ¶
ServeCustomTLS method serves the application with TLS encryption and custom server configuration.
func (*Cherry) ServeHTTP ¶
func (c *Cherry) ServeHTTP(rw http.ResponseWriter, r *http.Request)
ServeHTTP satisfies the http.Handler interface.
func (*Cherry) ServeTLS ¶
ServeTLS method serves the application one the given port with TLS encryption.
func (*Cherry) SetErrorHandler ¶
func (c *Cherry) SetErrorHandler(h ErrorHandlerFunc)
SetErrorHandler sets a centralized errorHandler that is invoked whenever a Handler returns an error.
func (*Cherry) SetMethodNotAllowed ¶
SetMethodNotAllowed sets a custom handler that is invoked whenever the router could not match the method against the predefined routes.
func (*Cherry) SetNotFound ¶
SetNotFound sets a custom handler that is invoked whenever the router could not match a route against the request url.
type Context ¶
type Context struct { // Context is a idiomatic way to pass information between requests. // More information about context.Context can be found here: // https://godoc.org/golang.org/x/net/context Context context.Context // contains filtered or unexported fields }
Context is required in each cherry Handler and can be used to pass information between requests.
func (*Context) DecodeJSON ¶
DecodeJSON is a helper that decodes the request Body to v. For a more in depth use of decoding and encoding JSON, use the std JSON package.
func (*Context) JSON ¶
JSON is a helper function for writing a JSON encoded representation of v to the ResponseWriter.
func (*Context) Param ¶
Param returns the url named parameter given in the route prefix by its name app.Get("/:name", ..) => ctx.Param("name").
func (*Context) Query ¶
Query returns the url query parameter by its name. app.Get("/api?limit=25", ..) => ctx.Query("limit").
func (*Context) Redirect ¶
Redirect redirects the request to the provided URL with the given status code.
func (*Context) Response ¶
func (c *Context) Response() http.ResponseWriter
Response returns a default http.ResponseWriter.
type ErrorHandlerFunc ¶
ErrorHandlerFunc used for centralize error handling when an error happens in Handler.