refactor: replace deprecated github.com/pkg/errors with errors pkg (#5577)
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// now not all implementation return those error codes
|
||||
|
||||
@@ -17,12 +17,12 @@ package etcd
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/pkg/errors"
|
||||
clientv3 "go.etcd.io/etcd/client/v3"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
@@ -82,7 +82,7 @@ func (e *EtcdConfiger) GetSection(section string) (map[string]string, error) {
|
||||
resp, err = e.client.Get(context.TODO(), e.prefix+section, clientv3.WithPrefix())
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "GetSection failed")
|
||||
return nil, fmt.Errorf("GetSection failed: %w", err)
|
||||
}
|
||||
res := make(map[string]string, len(resp.Kvs))
|
||||
for _, kv := range resp.Kvs {
|
||||
@@ -101,7 +101,7 @@ func (e *EtcdConfiger) SaveConfigFile(filename string) error {
|
||||
func (e *EtcdConfiger) Unmarshaler(prefix string, obj interface{}, opt ...config.DecodeOption) error {
|
||||
res, err := e.GetSection(prefix)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, fmt.Sprintf("could not read config with prefix: %s", prefix))
|
||||
return fmt.Errorf("could not read config with prefix: %s: %w", prefix, err)
|
||||
}
|
||||
|
||||
prefixLen := len(e.prefix + prefix)
|
||||
@@ -158,7 +158,7 @@ func (provider *EtcdConfigerProvider) ParseData(data []byte) (config.Configer, e
|
||||
cfg := &clientv3.Config{}
|
||||
err := json.Unmarshal(data, cfg)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "parse data to etcd config failed, please check your input")
|
||||
return nil, fmt.Errorf("parse data to etcd config failed, please check your input: %w", err)
|
||||
}
|
||||
|
||||
cfg.DialOptions = []grpc.DialOption{
|
||||
@@ -168,7 +168,7 @@ func (provider *EtcdConfigerProvider) ParseData(data []byte) (config.Configer, e
|
||||
}
|
||||
client, err := clientv3.New(*cfg)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "create etcd client failed")
|
||||
return nil, fmt.Errorf("create etcd client failed: %w", err)
|
||||
}
|
||||
|
||||
return newEtcdConfiger(client, ""), nil
|
||||
@@ -182,7 +182,7 @@ func get(client *clientv3.Client, key string) (*clientv3.GetResponse, error) {
|
||||
resp, err = client.Get(context.Background(), key)
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, fmt.Sprintf("read config from etcd with key %s failed", key))
|
||||
return nil, fmt.Errorf("read config from etcd with key %s failed: %w", key, err)
|
||||
}
|
||||
return resp, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user