forked from Fuyu/router
Use net/http for default handler messages
This commit is contained in:
parent
45ec83b9d3
commit
2c930bacf1
@ -35,6 +35,11 @@ func (c *Context) String(code int, s string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StatusText returns the given status code with the matching status text
|
||||||
|
func (c *Context) StatusText(code int) error {
|
||||||
|
return c.String(code, http.StatusText(code))
|
||||||
|
}
|
||||||
|
|
||||||
// NoContent returns the given status code without writing anything to the body
|
// NoContent returns the given status code without writing anything to the body
|
||||||
func (c *Context) NoContent(code int) error {
|
func (c *Context) NoContent(code int) error {
|
||||||
c.Response.WriteHeader(code)
|
c.Response.WriteHeader(code)
|
||||||
|
@ -2,20 +2,19 @@ package router
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
func defaultNotFoundHandler(c *Context) error {
|
func defaultNotFoundHandler(c *Context) error {
|
||||||
return c.String(404, `not found`)
|
return c.StatusText(http.StatusNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultMethodNotAllowedHandler(c *Context) error {
|
func defaultMethodNotAllowedHandler(c *Context) error {
|
||||||
return c.String(504, `method not allowed`)
|
return c.StatusText(http.StatusMethodNotAllowed)
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultErrorHandler(c *Context, err interface{}) {
|
func defaultErrorHandler(c *Context, err interface{}) {
|
||||||
fmt.Println(err)
|
_ = c.StatusText(http.StatusInternalServerError)
|
||||||
c.String(500, `internal server error`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultReader(c *Context, dst interface{}) bool {
|
func defaultReader(c *Context, dst interface{}) bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user