Status

Status allows to consult or modify the HTTP status code of the response.

If you want to know when Response may be modified, consult the documentation of the Lifecycle.


Methods

MethodDescription
GetCode() intReturns the current HTTP status code.
SetCode(status)Set the HTTP status code of the response.

Get the status code

Use GetCode() to know the current HTTP status code.

gox
status := ctx.Response.Status.GetCode()

if status == 404 {
	return <h1>Página no encontrada</h1>
}

Set the status code

Use SetCode() to modify the HTTP status code of the response.

gox
ctx.Response.Status.SetCode(404)

return <h1>Página no encontrada</h1>

The status code can be amended as many times as necessary while Response remain modifiable.


Best practices

  • It uses HTTP status codes appropriate for each response.
  • Configure the status code before you end the response.
  • Use GetCode() only when you need to know the current state.

See also

Next step

Continue with the documentation for DoneWith to know how to finish an request immediately and control the running flow.

DoneWith()