Response

c.Response equals to http.ResponseWriter.

Text

func text(c *clevergo.Context) error {
    return c.String(http.StatusOK, "hello world")
    // return c.Stringf(http.StatusOK, "hello %s", "foobar")
}

HTML

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>"))
}

Render

Renders a template, see Views.

JSON

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"}`))
}

JSONP

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",
    })
}

XML

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

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

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"))
}

Redirect

func redirect(c *clevergo.Context) error {
    c.Redirect("/login", http.StatusFound)
    return nil
}

SendFile

Sends a file to browser.

func download(c *clevergo.Context) error {
    buf := bytes.NewReader([]byte("bar"))
    return c.SendFile("foo.txt", buf)
}

Shortcuts

Method
Context.Errorhttp.Error
Context.NotFoundhttp.NotFoud
Context.Redirecthttp.Redirect
Context.SetCookiehttp.SetCookie
Context.Writehttp.ResponseWriter.Write
Context.WriteHeaderhttp.ResponseWriter.WriteHeader
comments powered by Disqus