c.Response
equals tohttp.ResponseWriter
.
func text(c *clevergo.Context) error {
return c.String(http.StatusOK, "hello world")
// return c.Stringf(http.StatusOK, "hello %s", "foobar")
}
func html(c *clevergo.Context) error {
return c.HTML(http.StatusOK, "<html><body>hello world</body></html>")
}
func htmlBlob(c *clevergo.Context) error {
return c.HTMLBlob(http.StatusOK, []byte("<html><body>hello world</body></html>"))
}
Renders a template, see Views.
func json(c *clevergo.Context) error {
return c.JSON(http.StatusOK, clevergo.Map{
"message": "hello world",
})
}
func jsonBlob(c *clevergo.Context) error {
return c.JSONBlob([]byte(`{"message":"hello world"}`))
}
func jsonp(c *clevergo.Context) error {
return c.JSONP(http.StatusOK, clevergo.Map{
"message": "hello world",
})
}
func jsonpCallback(c *clevergo.Context) error {
return c.JSONPCallback(http.StatusOK, "myCallback", clevergo.Map{
"message": "hello world",
})
}
func xml(c *clevergo.Context) error {
return c.XML(http.StatusOK, clevergo.Map{
"message": "hello world",
})
}
func xmlBlob(c *clevergo.Context) error {
return c.XMLBlob(http.StatusOK, []byte(`<xml><message>hello world</message></xml>`))
}
Emit
emits a response with the given code, content type and string data.
func emit(c *clevergo.Context) error {
return c.Emit(http.StatusOK, "text/html", "data")
}
Blob
emits a response with the given code, content type and byte slice data.
func blob(c *clevergo.Context) error {
return c.Blob(http.StatusOK, "text/html", []byte("data"))
}
func redirect(c *clevergo.Context) error {
c.Redirect("/login", http.StatusFound)
return nil
}
Sends a file to browser.
func download(c *clevergo.Context) error {
buf := bytes.NewReader([]byte("bar"))
return c.SendFile("foo.txt", buf)
}
Method | |
---|---|
Context.Error | http.Error |
Context.NotFound | http.NotFoud |
Context.Redirect | http.Redirect |
Context.SetCookie | http.SetCookie |
Context.Write | http.ResponseWriter.Write |
Context.WriteHeader | http.ResponseWriter.WriteHeader |