-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext_mojito.go
45 lines (36 loc) · 1.01 KB
/
context_mojito.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package mojito
import (
"github.com/go-mojito/mojito/pkg/router"
)
type mojitoContext struct {
router.Context
}
// JSON implements Context
func (ctx *mojitoContext) JSON(body interface{}) error {
return ctx.Response().WriteJSON(body, false)
}
// PrettyJSON implements Context
func (ctx *mojitoContext) PrettyJSON(body interface{}) error {
return ctx.Response().WriteJSON(body, true)
}
// ReadJSON implements Context
func (ctx *mojitoContext) ReadJSON(obj interface{}) error {
return ctx.Request().ParseJSON(obj)
}
// ReadXML implements Context
func (ctx *mojitoContext) ReadXML(obj interface{}) error {
return ctx.Request().ParseXML(obj)
}
// Status will set the HTTP status code on the response
func (ctx *mojitoContext) Status(code int) {
ctx.Response().WriteHeader(code)
}
// String will write a string to the response body
func (ctx *mojitoContext) String(body string) error {
return ctx.Response().WriteString(body)
}
func newMojitoContext(ctx router.Context) Context {
return &mojitoContext{
Context: ctx,
}
}