Skip to content

Commit

Permalink
add context method WriteJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
dworld committed Nov 13, 2014
1 parent aaeb1c9 commit 85af278
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions context_render.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package xingyun

import (
"encoding/json"
"mime"
"strings"
)
Expand All @@ -20,6 +21,7 @@ func (ctx *Context) SetContentType(val string) string {
}
return ctype
}

func (ctx *Context) WriteString(s string) {
_, err := ctx.Write([]byte(s))
if err != nil {
Expand All @@ -28,6 +30,14 @@ func (ctx *Context) WriteString(s string) {
}
}

func (ctx *Context) WriteJSON(obj interface{}) {
bs, err := json.Marshal(obj)
if err != nil {
panic(err)
}
ctx.Write(bs)
}

func (ctx *Context) NotModified() {
ctx.WriteHeader(304)
}
Expand Down

0 comments on commit 85af278

Please sign in to comment.