Skip to content

controller #

struct Controller #

struct Controller {
}

Controller is the base struct that all controllers can embed It provides a common type for controller pattern (currently empty)

fn (Controller) html #

fn (c &Controller) html(mut ctx http.Context, status int, body string) http.Response

html renders HTML response

fn (Controller) text #

fn (c &Controller) text(mut ctx http.Context, status int, body string) http.Response

text renders plain text response

fn (Controller) json #

fn (c &Controller) json[T](mut ctx http.Context, status int, data T) http.Response

json renders JSON response

fn (Controller) redirect #

fn (c &Controller) redirect(mut ctx http.Context, url string, status int) http.Response

redirect returns a redirect response

fn (Controller) redirect_temporary #

fn (c &Controller) redirect_temporary(mut ctx http.Context, url string) http.Response

redirect_temporary returns a 302 redirect

fn (Controller) redirect_permanent #

fn (c &Controller) redirect_permanent(mut ctx http.Context, url string) http.Response

redirect_permanent returns a 301 redirect

fn (Controller) param #

fn (c &Controller) param(ctx &http.Context, name string) string

param gets a route parameter

fn (Controller) query #

fn (c &Controller) query(ctx &http.Context, name string) string

query gets a query string parameter

fn (Controller) form #

fn (c &Controller) form(mut ctx http.Context, name string) string

form gets a form value

fn (Controller) not_found #

fn (c &Controller) not_found(mut ctx http.Context, message string) http.Response

not_found returns 404 response

fn (Controller) internal_error #

fn (c &Controller) internal_error(mut ctx http.Context, message string) http.Response

internal_error returns 500 response

fn (Controller) bad_request #

fn (c &Controller) bad_request(mut ctx http.Context, message string) http.Response

bad_request returns 400 response

fn (Controller) unauthorized #

fn (c &Controller) unauthorized(mut ctx http.Context, message string) http.Response

unauthorized returns 401 response

fn (Controller) forbidden #

fn (c &Controller) forbidden(mut ctx http.Context, message string) http.Response

forbidden returns 403 response