Events and Listeners
There are next request level events dispatched by web Kernel of Gkernel framework:
RequestReceived
Is being dispatched after request was received by the framework but before it was passed to controller. Can be used to read user's session from the storage, for authentication & authorization, etc.
RequestReceived
Event has next methods:
StopPropagation()
- to stop Event's propagation inside Listeners ChainIsPropagationStopped() bool
- returns if propagation of Event was stoppedGetRequest() *http.Request
- returns Request objectRequestContextAppend(key, val interface{})
- appends provided val object to Request's contextGetResponseWriter() http.ResponseWriter
- returns ResponseWriter object associated with current RequestGetResponse() response.Response
- gets Response object provided to this Event. InitiallyRequestReceived
Event has no Response (method returnsnil
)SetResponse(responseObj response.Response)
- stops Event's propagation and sends provided Response to user.
RequestProcessed
Is being dispatched after Controller has processed Request. Contains Response object returned from Controller.
RequestProcessed
Event has next methods:
StopPropagation()
- to stop Event's propagation inside Listeners ChainIsPropagationStopped() bool
- returns if propagation of Event was stoppedGetRequest() *http.Request
- returns Request objectRequestContextAppend(key, val interface{})
- appends provided val object to Request's contextGetResponseWriter() http.ResponseWriter
- returns ResponseWriter object associated with current RequestGetResponse() response.Response
- gets Response object provided to this Event. Initially this will be Response returned by ControllerSetResponse(responseObj response.Response)
- sets Response object. Notice: unlikeRequestReceived.SetResponse()
this method does not stop Event's propagation
ResponseBeforeSend
Is being dispatched after RequestProcessed
Event was processed. Can modify Response but can not replace it with new object.
ResponseBeforeSend
Event has next methods:
StopPropagation()
- to stop Event's propagation inside Listeners ChainIsPropagationStopped() bool
- returns if propagation of Event was stoppedGetRequest() *http.Request
- returns Request objectRequestContextAppend(key, val interface{})
- appends provided val object to Request's contextGetResponseWriter() http.ResponseWriter
- returns ResponseWriter object associated with current RequestGetResponse() response.Response
- gets Response object
RequestTermination
Is being dispatched after Response was sent to user. Can be used for logs exporting and others after-request activities.
RequestTermination
Event has next methods:
StopPropagation()
- to stop Event's propagation inside Listeners ChainIsPropagationStopped() bool
- returns if propagation of Event was stoppedGetRequest() *http.Request
- returns Request objectGetResponse() response.Response
- gets Response object
RuntimeError
In case of panic during Request processing
Gkernel automatically recovers that panic, creates RuntimeError
object to represent that panic and dispatches RuntimeError.
RuntimeError
Event has next methods:
StopPropagation()
- to stop Event's propagation inside Listeners ChainIsPropagationStopped() bool
- returns if propagation of Event was stoppedGetRequest() *http.Request
- returns Request objectRequestContextAppend(key, val interface{})
- appends provided val object to Request's contextGetResponseWriter() http.ResponseWriter
- returns ResponseWriter object associated with current RequestGetResponse() response.Response
- gets Response object provided to this Event. InitiallyRuntimeError
Event has no Response (method returnsnil
)SetResponse(responseObj response.Response)
- stops Event's propagation and sends provided Response to user.GetError() *kernelError.RuntimeError
- returnsRuntimeError
object that represents recovered panic