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
| Method | Description |
|---|---|
GetCode() int | Returns 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.
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.
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.