1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-14 17:10:54 +00:00
Beego/context/response/renderer.go

40 lines
727 B
Go
Raw Normal View History

2017-04-21 12:26:41 +00:00
package response
import (
"strconv"
beecontext "github.com/astaxie/beego/context"
)
2017-04-30 16:28:26 +00:00
// Renderer defines an http response renderer
2017-04-21 12:26:41 +00:00
type Renderer interface {
Render(ctx *beecontext.Context)
}
type rendererFunc func(ctx *beecontext.Context)
func (f rendererFunc) Render(ctx *beecontext.Context) {
f(ctx)
}
2017-04-30 16:28:26 +00:00
// StatusCode sets the http response status code
2017-04-21 12:26:41 +00:00
type StatusCode int
func (s StatusCode) Error() string {
return strconv.Itoa(int(s))
}
2017-04-30 16:28:26 +00:00
// Render sets the http status code
2017-04-21 12:26:41 +00:00
func (s StatusCode) Render(ctx *beecontext.Context) {
ctx.Output.SetStatus(int(s))
}
2017-04-22 22:33:50 +00:00
type statusCodeWithRender struct {
statusCode int
rendererFunc
}
func (s statusCodeWithRender) Error() string {
return strconv.Itoa(s.statusCode)
}