forked from TrueCloudLab/frostfs-node
[#219] morph: Resolve containedctx linter
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
56282edf02
commit
e815b19101
9 changed files with 43 additions and 54 deletions
|
@ -29,10 +29,7 @@ type Option func(*cfg)
|
|||
type Callback func()
|
||||
|
||||
// groups the configurations with default values.
|
||||
// nolint: containedctx
|
||||
type cfg struct {
|
||||
ctx context.Context // neo-go client context
|
||||
|
||||
dialTimeout time.Duration // client dial timeout
|
||||
|
||||
logger *logger.Logger // logging component
|
||||
|
@ -57,7 +54,6 @@ const (
|
|||
|
||||
func defaultConfig() *cfg {
|
||||
return &cfg{
|
||||
ctx: context.Background(),
|
||||
dialTimeout: defaultDialTimeout,
|
||||
logger: &logger.Logger{Logger: zap.L()},
|
||||
waitInterval: defaultWaitInterval,
|
||||
|
@ -84,7 +80,7 @@ func defaultConfig() *cfg {
|
|||
// If desired option satisfies the default value, it can be omitted.
|
||||
// If multiple options of the same config value are supplied,
|
||||
// the option with the highest index in the arguments will be used.
|
||||
func New(key *keys.PrivateKey, opts ...Option) (*Client, error) {
|
||||
func New(ctx context.Context, key *keys.PrivateKey, opts ...Option) (*Client, error) {
|
||||
if key == nil {
|
||||
panic("empty private key")
|
||||
}
|
||||
|
@ -142,20 +138,20 @@ func New(key *keys.PrivateKey, opts ...Option) (*Client, error) {
|
|||
return nil, fmt.Errorf("could not create RPC actor: %w", err)
|
||||
}
|
||||
} else {
|
||||
cli.client, act, err = cli.newCli(cli.endpoints.list[0].Address)
|
||||
cli.client, act, err = cli.newCli(ctx, cli.endpoints.list[0].Address)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not create RPC client: %w", err)
|
||||
}
|
||||
}
|
||||
cli.setActor(act)
|
||||
|
||||
go cli.notificationLoop()
|
||||
go cli.notificationLoop(ctx)
|
||||
|
||||
return cli, nil
|
||||
}
|
||||
|
||||
func (c *Client) newCli(endpoint string) (*rpcclient.WSClient, *actor.Actor, error) {
|
||||
cli, err := rpcclient.NewWS(c.cfg.ctx, endpoint, rpcclient.Options{
|
||||
func (c *Client) newCli(ctx context.Context, endpoint string) (*rpcclient.WSClient, *actor.Actor, error) {
|
||||
cli, err := rpcclient.NewWS(ctx, endpoint, rpcclient.Options{
|
||||
DialTimeout: c.cfg.dialTimeout,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -201,21 +197,6 @@ func newClientCache() cache {
|
|||
}
|
||||
}
|
||||
|
||||
// WithContext returns a client constructor option that
|
||||
// specifies the neo-go client context.
|
||||
//
|
||||
// Ignores nil value. Has no effect if WithSingleClient
|
||||
// is provided.
|
||||
//
|
||||
// If option not provided, context.Background() is used.
|
||||
func WithContext(ctx context.Context) Option {
|
||||
return func(c *cfg) {
|
||||
if ctx != nil {
|
||||
c.ctx = ctx
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WithDialTimeout returns a client constructor option
|
||||
// that specifies neo-go client dial timeout duration.
|
||||
//
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue