2020-09-02 12:36:53 +00:00
|
|
|
package context
|
|
|
|
|
|
|
|
import (
|
2020-11-26 09:48:29 +00:00
|
|
|
"net/http"
|
2020-12-12 13:28:58 +00:00
|
|
|
"strconv"
|
2020-09-02 12:36:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2020-12-12 13:28:58 +00:00
|
|
|
//BadRequest indicates HTTP error 400
|
2020-09-02 12:36:53 +00:00
|
|
|
BadRequest StatusCode = http.StatusBadRequest
|
|
|
|
|
2020-12-12 13:28:58 +00:00
|
|
|
//NotFound indicates HTTP error 404
|
2020-09-02 12:36:53 +00:00
|
|
|
NotFound StatusCode = http.StatusNotFound
|
|
|
|
)
|
|
|
|
|
2020-12-12 13:28:58 +00:00
|
|
|
// StatusCode sets the HTTP response status code
|
2020-09-02 12:36:53 +00:00
|
|
|
type StatusCode int
|
|
|
|
|
|
|
|
func (s StatusCode) Error() string {
|
|
|
|
return strconv.Itoa(int(s))
|
|
|
|
}
|
|
|
|
|
2020-12-12 13:28:58 +00:00
|
|
|
// Render sets the HTTP status code
|
2020-09-02 12:36:53 +00:00
|
|
|
func (s StatusCode) Render(ctx *Context) {
|
|
|
|
ctx.Output.SetStatus(int(s))
|
|
|
|
}
|