forked from Fuyu/router
Fix function comments
This commit is contained in:
parent
0990f5bafe
commit
890ff550eb
@ -20,6 +20,8 @@ func newContext(router *Router, res http.ResponseWriter, req *http.Request, para
|
||||
return &Context{router, req, res, param.ByName, make(map[string]interface{})}
|
||||
}
|
||||
|
||||
// QueryParam returns the specified parameter from the query string.
|
||||
// Returns an empty string if it doesn't exist. Returns the first parameter if multiple instances exist
|
||||
func (c *Context) QueryParam(param string) string {
|
||||
params := c.Request.URL.Query()[param]
|
||||
if params == nil {
|
||||
@ -29,12 +31,13 @@ func (c *Context) QueryParam(param string) string {
|
||||
return params[0]
|
||||
}
|
||||
|
||||
// Redirect sends a redirect to the client
|
||||
func (c *Context) Redirect(code int, url string) error {
|
||||
http.Redirect(c.Response, c.Request, url, code)
|
||||
return nil
|
||||
}
|
||||
|
||||
// String returns the given status code and writes the bytes to the body
|
||||
// Bytes returns the given status code and writes the bytes to the body
|
||||
func (c *Context) Bytes(code int, b []byte) error {
|
||||
c.Response.WriteHeader(code)
|
||||
_, err := c.Response.Write(b)
|
||||
@ -67,6 +70,7 @@ func (c *Context) JSON(code int, data interface{}) error {
|
||||
return json.NewEncoder(c.Response).Encode(data) // TODO: Encode to buffer first to prevent partial responses on error
|
||||
}
|
||||
|
||||
// Render renders a templating using the Renderer set in router
|
||||
func (c *Context) Render(code int, template string, data interface{}) error {
|
||||
if c.router.Renderer == nil {
|
||||
panic(`Cannot call render without a renderer set`)
|
||||
|
@ -23,7 +23,7 @@ type ErrorHandle func(*Context, interface{})
|
||||
// Middleware is a function that runs before your route, it gets the next handler as a parameter
|
||||
type Middleware func(Handle) Handle
|
||||
|
||||
// Binder reads input to dst, returns true is successful
|
||||
// Reader reads input to dst, returns true if successful
|
||||
type Reader func(c *Context, dst interface{}) (bool, error)
|
||||
|
||||
// Router is the router itself
|
||||
@ -159,7 +159,7 @@ func handlePOST(r *Router, f interface{}) Handle {
|
||||
|
||||
if r.Reader != nil {
|
||||
ok, err := r.Reader(c, data.Interface())
|
||||
c.Request.Body.Close()
|
||||
_ = c.Request.Body.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user