forked from TrueCloudLab/frostfs-api-go
[#337] client: Add option to specify callback of response information
There is a need to analyze some response information in API client. Define `ResponseMetaInfo` structure of response information. Add `WithResponseInfoHandler` client option which allows to set the response info callback. The callback is called right after any response is received. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
3844a3ac74
commit
da89c2b71f
8 changed files with 139 additions and 0 deletions
37
pkg/client/response.go
Normal file
37
pkg/client/response.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
||||
)
|
||||
|
||||
// ResponseMetaInfo groups meta information about any NeoFS API response.
|
||||
type ResponseMetaInfo struct {
|
||||
key []byte
|
||||
}
|
||||
|
||||
// ResponderKey returns responder's public key in a binary format.
|
||||
//
|
||||
// Result must not be mutated.
|
||||
func (x ResponseMetaInfo) ResponderKey() []byte {
|
||||
return x.key
|
||||
}
|
||||
|
||||
// WithResponseInfoHandler allows to specify handler of response meta information for the all Client operations.
|
||||
// The handler is called right after the response is received. Client returns handler's error immediately.
|
||||
func WithResponseInfoHandler(f func(ResponseMetaInfo) error) Option {
|
||||
return func(opts *clientOptions) {
|
||||
opts.cbRespInfo = f
|
||||
}
|
||||
}
|
||||
|
||||
func (c *clientImpl) handleResponseInfoV2(opts *callOptions, resp interface {
|
||||
GetVerificationHeader() *session.ResponseVerificationHeader
|
||||
}) error {
|
||||
if c.opts.cbRespInfo == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return c.opts.cbRespInfo(ResponseMetaInfo{
|
||||
key: resp.GetVerificationHeader().GetBodySignature().GetKey(),
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue