DoneWith()
DoneWith() complete the execution of the current page or action and continue the request using an alternative response.
You can use a component provided by the GOX developer or custom error system.
If you want to know when Response may be modified, consult the documentation of the Lifecycle.
Syntax
ctx.Response.DoneWith(status)
ctx.Response.DoneWith(status, component) | Parameter | Description |
|---|---|
status | HTTP status code used to end the response. |
component | Optional component used to generate the response. |
Execution flow
When GOX runs DoneWith(), the current page or action ends immediately and the request continues to use an alternative response.
if !validate.IsLogin(ctx) {
// La ejecución finaliza aquí.
ctx.Response.DoneWith(401)
// Este return no es necesario.
return
} If a component is not provided, GOX continues the request flow using the custom error system.
For more information, please consult the documentation of Custom errors.
Use a component
It is also possible to provide a component to generate the response.
func AccessDenied(ctx *gox.Context) gox.Component {
return <h1>Acceso denegado</h1>
}
ctx.Response.DoneWith(403, AccessDenied) When a component is provided, GOX uses it to generate the response rather than continue with the custom error system.
Best practices
- Configure
Responsebefore callingDoneWith(). - Use
DoneWith()when the execution is to be completed immediately. - It uses a component when the response is specific to a page.
- It uses error pages when the response must be reused throughout the application.
To learn more about PagesSee your documentation. To learn more about Templates, check your documentation.