Exemplo n.º 1
0
func responseMessage(resp io.Writer, ctx *jas.Context) int {
	if ctx.Error != nil {
		ctx.Status = ctx.Error.Status()
	}

	var written int
	jsonBytes, _ := json.Marshal(ctx.Data)
	if ctx.Callback != "" { // handle JSONP
		ctx.ResponseHeader.Set("Content-Type", "application/javascript; charset=utf-8")

		a, _ := resp.Write([]byte(ctx.Callback + "("))
		b, _ := resp.Write(jsonBytes)
		c, _ := resp.Write([]byte(");"))

		written = a + b + c
	} else {
		written, _ = resp.Write(jsonBytes)
	}

	return written
}
Exemplo n.º 2
0
// Get responds on the root API handler ("/api/") with 303 SeeOther
// and a link to the API documentation on the project homepage.
func (*Api) Get(ctx *jas.Context) {
	ctx.Status = http.StatusSeeOther
	ctx.ResponseHeader.Set("Location", APIDocs)
	ctx.Data = http.StatusText(http.StatusSeeOther) + ": " + APIDocs
}