Gosip provides an events system with a set of handlers that can be optionally defined to track different client communication aspects such as request tracking, retries and response error logging, to name just a few.
To define the handlers Hooks object should be configured and passed to gosip.SPClient struct.
varauthCnfggosip.AuthCnfg// ... auth config initiation is omitted&gosip.SPClient{AuthCnfg:authCnfg,Hooks:&gosip.HookHandlers{// handlers function definition},}
The following handlers are available at the moment:
// HookHandlers struct to configure events handlerstypeHookHandlersstruct{OnErrorfunc(event*HookEvent)// when error appearedOnRetryfunc(event*HookEvent)// before retry requestOnRequestfunc(event*HookEvent)// before request is sentOnResponsefunc(event*HookEvent)// after response is received}
All of the handlers are optional.
A handler receives HookEvent pointer which contains request pointer, response status code, and error (if applicable for an event), and time information to track duration since a request started an event happened.
Hooks sample:
Hooks can be handy for global logging streaming and metrics collection.
It is recommended using asynchronous and only lightweight logic inside hooks.