forked from TrueCloudLab/frostfs-node
751147793f
Note that we cannot mark `--rpc-endpoint` flag as required because it can be taken from config. Before: ``` Error: can't create N3 client: failed to get network magic: Post "": unsupported protocol scheme "" ``` Now: ``` Error: can't create N3 client: missing endpoint ``` Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
25 lines
518 B
Go
25 lines
518 B
Go
package morph
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/rpc/client"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
func getN3Client(v *viper.Viper) (*client.Client, error) {
|
|
ctx := context.Background() // FIXME(@fyrchik): timeout context
|
|
endpoint := v.GetString(endpointFlag)
|
|
if endpoint == "" {
|
|
return nil, errors.New("missing endpoint")
|
|
}
|
|
c, err := client.New(ctx, endpoint, client.Options{})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if err := c.Init(); err != nil {
|
|
return nil, err
|
|
}
|
|
return c, nil
|
|
}
|