From ca3e80b76b5662ee15fe25f40b5dde27c8f43218 Mon Sep 17 00:00:00 2001 From: "Alessandro (Ale) Segala" <43508+ItalyPaleAle@users.noreply.github.com> Date: Thu, 3 Nov 2022 22:19:21 -0700 Subject: [PATCH] Updated depguard linter config (#2245) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Updated depguard linter config 1. Add older (pre-v4) versions of `github.com/cenkalti/backoff` to the denylist 2. Add `github.com/agrea/ptr` to the denylist (use `github.com/dapr/kit/ptr` instead) 3. Fixed error messages for denied deps Port of dapr/dapr#5438 Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com> * ⚙️🧹 Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com> * Remove some github.com/pkg/errors Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com> * make modtidy-all after rebase Signed-off-by: Bernd Verst <4535280+berndverst@users.noreply.github.com> Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com> Signed-off-by: Bernd Verst <4535280+berndverst@users.noreply.github.com> Co-authored-by: Bernd Verst <4535280+berndverst@users.noreply.github.com> Co-authored-by: Dapr Bot <56698301+dapr-bot@users.noreply.github.com> --- .golangci.yml | 13 ++++---- bindings/mysql/mysql.go | 32 +++++++++---------- go.mod | 1 - go.sum | 2 -- state/aerospike/aerospike.go | 4 +-- state/alicloud/tablestore/tablestore.go | 4 +-- state/alicloud/tablestore/tablestore_test.go | 6 ++-- state/azure/blobstorage/blobstorage.go | 4 +-- state/cockroachdb/cockroachdb_access.go | 9 +++--- state/cockroachdb/cockroachdb_query.go | 5 ++- state/cockroachdb/cockroachdb_query_test.go | 4 +-- state/couchbase/couchbase.go | 4 +-- state/hashicorp/consul/consul.go | 4 +-- state/in-memory/in_memory_test.go | 6 ++-- state/mongodb/mongodb.go | 4 +-- state/postgresql/postgresdbaccess.go | 10 +++--- state/postgresql/postgresql_query.go | 5 ++- state/redis/redis.go | 4 +-- state/redis/redis_test.go | 10 +++--- state/rethinkdb/rethinkdb.go | 4 +-- state/sqlserver/sqlserver.go | 4 +-- state/zookeeper/zk.go | 4 +-- state/zookeeper/zk_test.go | 4 +-- .../state/azure/blobstorage/go.mod | 1 - .../state/azure/blobstorage/go.sum | 1 - tests/certification/state/mongodb/go.mod | 1 - tests/certification/state/mongodb/go.sum | 1 - tests/certification/state/postgresql/go.mod | 1 - tests/certification/state/postgresql/go.sum | 1 - tests/certification/state/redis/go.mod | 1 - tests/certification/state/redis/go.sum | 1 - tests/certification/state/sqlserver/go.mod | 1 - tests/certification/state/sqlserver/go.sum | 1 - 33 files changed, 69 insertions(+), 88 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 26ea4cffa..c10f1e9a3 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -116,13 +116,14 @@ linters-settings: # minimal occurrences count to trigger, 3 by default min-occurrences: 5 depguard: - list-type: blacklist + list-type: denylist include-go-root: false - packages: - - github.com/Sirupsen/logrus - packages-with-error-messages: - # specify an error message to output when a blacklisted package is used - github.com/Sirupsen/logrus: "must use github.com/dapr/kit/logger" + packages-with-error-message: + - "github.com/Sirupsen/logrus": "must use github.com/dapr/kit/logger" + - "github.com/agrea/ptr": "must use github.com/dapr/kit/ptr" + - "github.com/cenkalti/backoff": "must use github.com/cenkalti/backoff/v4" + - "github.com/cenkalti/backoff/v2": "must use github.com/cenkalti/backoff/v4" + - "github.com/cenkalti/backoff/v3": "must use github.com/cenkalti/backoff/v4" misspell: # Correct spellings using locale preferences for US or UK. # Default is to use a neutral variety of English. diff --git a/bindings/mysql/mysql.go b/bindings/mysql/mysql.go index 3fb6d9976..9769ee7c6 100644 --- a/bindings/mysql/mysql.go +++ b/bindings/mysql/mysql.go @@ -20,6 +20,7 @@ import ( "database/sql" "database/sql/driver" "encoding/json" + "errors" "fmt" "os" "reflect" @@ -27,7 +28,6 @@ import ( "time" "github.com/go-sql-driver/mysql" - "github.com/pkg/errors" "github.com/dapr/components-contrib/bindings" "github.com/dapr/kit/logger" @@ -117,7 +117,7 @@ func (m *Mysql) Init(metadata bindings.Metadata) error { err = db.Ping() if err != nil { - return errors.Wrap(err, "unable to ping the DB") + return fmt.Errorf("unable to ping the DB: %w", err) } m.db = db @@ -128,7 +128,7 @@ func (m *Mysql) Init(metadata bindings.Metadata) error { // Invoke handles all invoke operations. func (m *Mysql) Invoke(ctx context.Context, req *bindings.InvokeRequest) (*bindings.InvokeResponse, error) { if req == nil { - return nil, errors.Errorf("invoke request required") + return nil, errors.New("invoke request required") } if req.Operation == closeOperation { @@ -136,13 +136,13 @@ func (m *Mysql) Invoke(ctx context.Context, req *bindings.InvokeRequest) (*bindi } if req.Metadata == nil { - return nil, errors.Errorf("metadata required") + return nil, errors.New("metadata required") } m.logger.Debugf("operation: %v", req.Operation) s, ok := req.Metadata[commandSQLKey] if !ok || s == "" { - return nil, errors.Errorf("required metadata not set: %s", commandSQLKey) + return nil, fmt.Errorf("required metadata not set: %s", commandSQLKey) } startTime := time.Now() @@ -171,7 +171,7 @@ func (m *Mysql) Invoke(ctx context.Context, req *bindings.InvokeRequest) (*bindi resp.Data = d default: - return nil, errors.Errorf("invalid operation type: %s. Expected %s, %s, or %s", + return nil, fmt.Errorf("invalid operation type: %s. Expected %s, %s, or %s", req.Operation, execOperation, queryOperation, closeOperation) } @@ -201,11 +201,9 @@ func (m *Mysql) Close() error { } func (m *Mysql) query(ctx context.Context, sql string) ([]byte, error) { - m.logger.Debugf("query: %s", sql) - rows, err := m.db.QueryContext(ctx, sql) if err != nil { - return nil, errors.Wrapf(err, "error executing %s", sql) + return nil, fmt.Errorf("error executing query: %w", err) } defer func() { @@ -215,7 +213,7 @@ func (m *Mysql) query(ctx context.Context, sql string) ([]byte, error) { result, err := m.jsonify(rows) if err != nil { - return nil, errors.Wrapf(err, "error marshalling query result for %s", sql) + return nil, fmt.Errorf("error marshalling query result for query: %w", err) } return result, nil @@ -226,7 +224,7 @@ func (m *Mysql) exec(ctx context.Context, sql string) (int64, error) { res, err := m.db.ExecContext(ctx, sql) if err != nil { - return 0, errors.Wrapf(err, "error executing %s", sql) + return 0, fmt.Errorf("error executing query: %w", err) } return res.RowsAffected() @@ -237,7 +235,7 @@ func propertyToInt(props map[string]string, key string, setter func(int)) error if i, err := strconv.Atoi(v); err == nil { setter(i) } else { - return errors.Wrapf(err, "error converitng %s:%s to int", key, v) + return fmt.Errorf("error converting %s:%s to int: %w", key, v, err) } } @@ -249,7 +247,7 @@ func propertyToDuration(props map[string]string, key string, setter func(time.Du if d, err := time.ParseDuration(v); err == nil { setter(d) } else { - return errors.Wrapf(err, "error converitng %s:%s to time duration", key, v) + return fmt.Errorf("error converting %s:%s to duration: %w", key, v, err) } } @@ -258,14 +256,14 @@ func propertyToDuration(props map[string]string, key string, setter func(time.Du func initDB(url, pemPath string) (*sql.DB, error) { if _, err := mysql.ParseDSN(url); err != nil { - return nil, errors.Wrapf(err, "illegal Data Source Name (DNS) specified by %s", connectionURLKey) + return nil, fmt.Errorf("illegal Data Source Name (DSN) specified by %s", connectionURLKey) } if pemPath != "" { rootCertPool := x509.NewCertPool() pem, err := os.ReadFile(pemPath) if err != nil { - return nil, errors.Wrapf(err, "Error reading PEM file from %s", pemPath) + return nil, fmt.Errorf("error reading PEM file from %s: %w", pemPath, err) } ok := rootCertPool.AppendCertsFromPEM(pem) @@ -275,13 +273,13 @@ func initDB(url, pemPath string) (*sql.DB, error) { err = mysql.RegisterTLSConfig("custom", &tls.Config{RootCAs: rootCertPool, MinVersion: tls.VersionTLS12}) if err != nil { - return nil, errors.Wrap(err, "Error register TLS config") + return nil, fmt.Errorf("error register TLS config: %w", err) } } db, err := sql.Open("mysql", url) if err != nil { - return nil, errors.Wrap(err, "error opening DB connection") + return nil, fmt.Errorf("error opening DB connection: %w", err) } return db, nil diff --git a/go.mod b/go.mod index 97b7c970b..c6268b28b 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,6 @@ require ( github.com/DATA-DOG/go-sqlmock v1.5.0 github.com/Shopify/sarama v1.37.2 github.com/aerospike/aerospike-client-go v4.5.2+incompatible - github.com/agrea/ptr v0.0.0-20180711073057-77a518d99b7b github.com/alibaba/sentinel-golang v1.0.4 github.com/alibabacloud-go/darabonba-openapi v0.2.1 github.com/alibabacloud-go/oos-20190601 v1.0.4 diff --git a/go.sum b/go.sum index baf8c92ac..886a0f3b3 100644 --- a/go.sum +++ b/go.sum @@ -208,8 +208,6 @@ github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw= github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRBij0P8= github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo= -github.com/agrea/ptr v0.0.0-20180711073057-77a518d99b7b h1:WMhlIaJkDgEQSVJQM06YV+cYUl1r5OY5//ijMXJNqtA= -github.com/agrea/ptr v0.0.0-20180711073057-77a518d99b7b/go.mod h1:Tie46d3UWzXpj+Fh9+DQTyaUxEpFBPOLXrnx7nxlKRo= github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU= github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY= github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= diff --git a/state/aerospike/aerospike.go b/state/aerospike/aerospike.go index 68f85654d..64235c344 100644 --- a/state/aerospike/aerospike.go +++ b/state/aerospike/aerospike.go @@ -22,11 +22,11 @@ import ( as "github.com/aerospike/aerospike-client-go" "github.com/aerospike/aerospike-client-go/types" - "github.com/agrea/ptr" jsoniter "github.com/json-iterator/go" "github.com/dapr/components-contrib/state" "github.com/dapr/kit/logger" + "github.com/dapr/kit/ptr" ) // metadata values. @@ -191,7 +191,7 @@ func (aspike *Aerospike) Get(req *state.GetRequest) (*state.GetResponse, error) return &state.GetResponse{ Data: value, - ETag: ptr.String(strconv.FormatUint(uint64(record.Generation), 10)), + ETag: ptr.Of(strconv.FormatUint(uint64(record.Generation), 10)), }, nil } diff --git a/state/alicloud/tablestore/tablestore.go b/state/alicloud/tablestore/tablestore.go index 6d5583d7c..d6a7bf97f 100644 --- a/state/alicloud/tablestore/tablestore.go +++ b/state/alicloud/tablestore/tablestore.go @@ -16,12 +16,12 @@ package tablestore import ( "encoding/json" - "github.com/agrea/ptr" "github.com/aliyun/aliyun-tablestore-go-sdk/tablestore" jsoniter "github.com/json-iterator/go" "github.com/dapr/components-contrib/state" "github.com/dapr/kit/logger" + "github.com/dapr/kit/ptr" ) const ( @@ -96,7 +96,7 @@ func (s *AliCloudTableStore) getResp(columns []*tablestore.AttributeColumn) *sta if column.ColumnName == stateValue { getResp.Data = unmarshal(column.Value) } else if column.ColumnName == sateEtag { - getResp.ETag = ptr.String(column.Value.(string)) + getResp.ETag = ptr.Of(column.Value.(string)) } } diff --git a/state/alicloud/tablestore/tablestore_test.go b/state/alicloud/tablestore/tablestore_test.go index d946a7be2..df3846a12 100644 --- a/state/alicloud/tablestore/tablestore_test.go +++ b/state/alicloud/tablestore/tablestore_test.go @@ -16,12 +16,12 @@ package tablestore import ( "testing" - "github.com/agrea/ptr" "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" "github.com/dapr/components-contrib/state" "github.com/dapr/kit/logger" + "github.com/dapr/kit/ptr" ) func TestTableStoreMetadata(t *testing.T) { @@ -61,7 +61,7 @@ func TestReadAndWrite(t *testing.T) { setReq := &state.SetRequest{ Key: "theFirstKey", Value: "value of key", - ETag: ptr.String("the etag"), + ETag: ptr.Of("the etag"), } err := store.Set(setReq) assert.Nil(t, err) @@ -81,7 +81,7 @@ func TestReadAndWrite(t *testing.T) { setReq := &state.SetRequest{ Key: "theSecondKey", Value: "1234", - ETag: ptr.String("the etag"), + ETag: ptr.Of("the etag"), } err := store.Set(setReq) assert.Nil(t, err) diff --git a/state/azure/blobstorage/blobstorage.go b/state/azure/blobstorage/blobstorage.go index cb70b95ea..e56e2c709 100644 --- a/state/azure/blobstorage/blobstorage.go +++ b/state/azure/blobstorage/blobstorage.go @@ -45,13 +45,13 @@ import ( "strings" "github.com/Azure/azure-storage-blob-go/azblob" - "github.com/agrea/ptr" jsoniter "github.com/json-iterator/go" azauth "github.com/dapr/components-contrib/internal/authentication/azure" mdutils "github.com/dapr/components-contrib/metadata" "github.com/dapr/components-contrib/state" "github.com/dapr/kit/logger" + "github.com/dapr/kit/ptr" ) const ( @@ -212,7 +212,7 @@ func (r *StateStore) readFile(ctx context.Context, req *state.GetRequest) (*stat return &state.GetResponse{ Data: data, - ETag: ptr.String(string(resp.ETag())), + ETag: ptr.Of(string(resp.ETag())), ContentType: &contentType, }, nil } diff --git a/state/cockroachdb/cockroachdb_access.go b/state/cockroachdb/cockroachdb_access.go index 9d85db381..d033031d3 100644 --- a/state/cockroachdb/cockroachdb_access.go +++ b/state/cockroachdb/cockroachdb_access.go @@ -21,13 +21,12 @@ import ( "fmt" "strconv" - "github.com/agrea/ptr" - "github.com/dapr/components-contrib/metadata" "github.com/dapr/components-contrib/state" "github.com/dapr/components-contrib/state/query" "github.com/dapr/components-contrib/state/utils" "github.com/dapr/kit/logger" + "github.com/dapr/kit/ptr" // Blank import for the underlying PostgreSQL driver. _ "github.com/jackc/pgx/v5/stdlib" @@ -207,7 +206,7 @@ func (p *cockroachDBAccess) Get(req *state.GetRequest) (*state.GetResponse, erro return &state.GetResponse{ Data: data, - ETag: ptr.String(strconv.Itoa(etag)), + ETag: ptr.Of(strconv.Itoa(etag)), Metadata: req.Metadata, ContentType: nil, }, nil @@ -215,7 +214,7 @@ func (p *cockroachDBAccess) Get(req *state.GetRequest) (*state.GetResponse, erro return &state.GetResponse{ Data: []byte(value), - ETag: ptr.String(strconv.Itoa(etag)), + ETag: ptr.Of(strconv.Itoa(etag)), Metadata: req.Metadata, ContentType: nil, }, nil @@ -348,7 +347,7 @@ func (p *cockroachDBAccess) Query(req *state.QueryRequest) (*state.QueryResponse query: "", params: []interface{}{}, limit: 0, - skip: ptr.Int64(0), + skip: ptr.Of[int64](0), } qbuilder := query.NewQueryBuilder(stateQuery) if err := qbuilder.BuildQuery(&req.Query); err != nil { diff --git a/state/cockroachdb/cockroachdb_query.go b/state/cockroachdb/cockroachdb_query.go index 5fffb006a..3631b58ac 100644 --- a/state/cockroachdb/cockroachdb_query.go +++ b/state/cockroachdb/cockroachdb_query.go @@ -19,11 +19,10 @@ import ( "strconv" "strings" - "github.com/agrea/ptr" - "github.com/dapr/components-contrib/state" "github.com/dapr/components-contrib/state/query" "github.com/dapr/kit/logger" + "github.com/dapr/kit/ptr" ) type Query struct { @@ -153,7 +152,7 @@ func (q *Query) execute(logger logger.Logger, db *sql.DB) ([]state.QueryItem, st result := state.QueryItem{ Key: key, Data: data, - ETag: ptr.String(strconv.Itoa(etag)), + ETag: ptr.Of(strconv.Itoa(etag)), Error: "", ContentType: nil, } diff --git a/state/cockroachdb/cockroachdb_query_test.go b/state/cockroachdb/cockroachdb_query_test.go index 34b5c9c94..73e185332 100644 --- a/state/cockroachdb/cockroachdb_query_test.go +++ b/state/cockroachdb/cockroachdb_query_test.go @@ -18,10 +18,10 @@ import ( "os" "testing" - "github.com/agrea/ptr" "github.com/stretchr/testify/assert" "github.com/dapr/components-contrib/state/query" + "github.com/dapr/kit/ptr" ) func TestPostgresqlQueryBuildQuery(t *testing.T) { @@ -67,7 +67,7 @@ func TestPostgresqlQueryBuildQuery(t *testing.T) { query: "", params: nil, limit: 0, - skip: ptr.Int64(0), + skip: ptr.Of[int64](0), } qbuilder := query.NewQueryBuilder(stateQuery) err = qbuilder.BuildQuery(&storeQuery) diff --git a/state/couchbase/couchbase.go b/state/couchbase/couchbase.go index d3e1a14a3..317886515 100644 --- a/state/couchbase/couchbase.go +++ b/state/couchbase/couchbase.go @@ -18,13 +18,13 @@ import ( "fmt" "strconv" - "github.com/agrea/ptr" jsoniter "github.com/json-iterator/go" "gopkg.in/couchbase/gocb.v1" "github.com/dapr/components-contrib/state" "github.com/dapr/components-contrib/state/utils" "github.com/dapr/kit/logger" + "github.com/dapr/kit/ptr" ) const ( @@ -201,7 +201,7 @@ func (cbs *Couchbase) Get(req *state.GetRequest) (*state.GetResponse, error) { return &state.GetResponse{ Data: data.([]byte), - ETag: ptr.String(strconv.FormatUint(uint64(cas), 10)), + ETag: ptr.Of(strconv.FormatUint(uint64(cas), 10)), }, nil } diff --git a/state/hashicorp/consul/consul.go b/state/hashicorp/consul/consul.go index b16e78b2f..5680d15a2 100644 --- a/state/hashicorp/consul/consul.go +++ b/state/hashicorp/consul/consul.go @@ -17,12 +17,12 @@ import ( "encoding/json" "fmt" - "github.com/agrea/ptr" "github.com/hashicorp/consul/api" "github.com/pkg/errors" "github.com/dapr/components-contrib/state" "github.com/dapr/kit/logger" + "github.com/dapr/kit/ptr" ) // Consul is a state store implementation for HashiCorp Consul. @@ -119,7 +119,7 @@ func (c *Consul) Get(req *state.GetRequest) (*state.GetResponse, error) { return &state.GetResponse{ Data: resp.Value, - ETag: ptr.String(queryMeta.LastContentHash), + ETag: ptr.Of(queryMeta.LastContentHash), }, nil } diff --git a/state/in-memory/in_memory_test.go b/state/in-memory/in_memory_test.go index 8a29c31ed..23625279e 100644 --- a/state/in-memory/in_memory_test.go +++ b/state/in-memory/in_memory_test.go @@ -17,11 +17,11 @@ import ( "testing" "time" - "github.com/agrea/ptr" "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" "github.com/dapr/kit/logger" + "github.com/dapr/kit/ptr" "github.com/dapr/components-contrib/state" ) @@ -41,7 +41,7 @@ func TestReadAndWrite(t *testing.T) { setReq := &state.SetRequest{ Key: keyA, Value: valueA, - ETag: ptr.String("the etag"), + ETag: ptr.Of("the etag"), } err := store.Set(setReq) assert.Nil(t, err) @@ -82,7 +82,7 @@ func TestReadAndWrite(t *testing.T) { setReq := &state.SetRequest{ Key: "theSecondKey", Value: "1234", - ETag: ptr.String("the etag"), + ETag: ptr.Of("the etag"), } err := store.Set(setReq) assert.Nil(t, err) diff --git a/state/mongodb/mongodb.go b/state/mongodb/mongodb.go index f4abc97e5..1a99293e4 100644 --- a/state/mongodb/mongodb.go +++ b/state/mongodb/mongodb.go @@ -23,7 +23,6 @@ import ( "strconv" "time" - "github.com/agrea/ptr" "github.com/google/uuid" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" @@ -35,6 +34,7 @@ import ( "github.com/dapr/components-contrib/state" "github.com/dapr/components-contrib/state/query" "github.com/dapr/kit/logger" + "github.com/dapr/kit/ptr" ) const ( @@ -259,7 +259,7 @@ func (m *MongoDB) Get(req *state.GetRequest) (*state.GetResponse, error) { return &state.GetResponse{ Data: data, - ETag: ptr.String(result.Etag), + ETag: ptr.Of(result.Etag), }, nil } diff --git a/state/postgresql/postgresdbaccess.go b/state/postgresql/postgresdbaccess.go index 16bb36874..9cdca16b7 100644 --- a/state/postgresql/postgresdbaccess.go +++ b/state/postgresql/postgresdbaccess.go @@ -21,13 +21,11 @@ import ( "strconv" "time" - "github.com/agrea/ptr" - "github.com/pkg/errors" - "github.com/dapr/components-contrib/state" "github.com/dapr/components-contrib/state/query" "github.com/dapr/components-contrib/state/utils" "github.com/dapr/kit/logger" + "github.com/dapr/kit/ptr" // Blank import for the underlying PostgreSQL driver. _ "github.com/jackc/pgx/v5/stdlib" @@ -232,14 +230,14 @@ func (p *postgresDBAccess) Get(req *state.GetRequest) (*state.GetResponse, error return &state.GetResponse{ Data: data, - ETag: ptr.String(strconv.Itoa(etag)), + ETag: ptr.Of(strconv.Itoa(etag)), Metadata: req.Metadata, }, nil } return &state.GetResponse{ Data: []byte(value), - ETag: ptr.String(strconv.Itoa(etag)), + ETag: ptr.Of(strconv.Itoa(etag)), Metadata: req.Metadata, }, nil } @@ -458,7 +456,7 @@ func propertyToDuration(props map[string]string, key string, setter func(time.Du if d, err := time.ParseDuration(v); err == nil { setter(d) } else { - return errors.Wrapf(err, "error converitng %s:%s to time duration", key, v) + return fmt.Errorf("error converitng %s:%s to time duration: %w", key, v, err) } } diff --git a/state/postgresql/postgresql_query.go b/state/postgresql/postgresql_query.go index b18866119..833618a6b 100644 --- a/state/postgresql/postgresql_query.go +++ b/state/postgresql/postgresql_query.go @@ -20,11 +20,10 @@ import ( "strconv" "strings" - "github.com/agrea/ptr" - "github.com/dapr/components-contrib/state" "github.com/dapr/components-contrib/state/query" "github.com/dapr/kit/logger" + "github.com/dapr/kit/ptr" ) type Query struct { @@ -159,7 +158,7 @@ func (q *Query) execute(logger logger.Logger, db *sql.DB) ([]state.QueryItem, st result := state.QueryItem{ Key: key, Data: data, - ETag: ptr.String(strconv.Itoa(etag)), + ETag: ptr.Of(strconv.Itoa(etag)), } ret = append(ret, result) } diff --git a/state/redis/redis.go b/state/redis/redis.go index 3ff7c55fe..03c47fc88 100644 --- a/state/redis/redis.go +++ b/state/redis/redis.go @@ -19,7 +19,6 @@ import ( "strconv" "strings" - "github.com/agrea/ptr" "github.com/go-redis/redis/v8" jsoniter "github.com/json-iterator/go" @@ -30,6 +29,7 @@ import ( "github.com/dapr/components-contrib/state/query" "github.com/dapr/components-contrib/state/utils" "github.com/dapr/kit/logger" + "github.com/dapr/kit/ptr" ) const ( @@ -476,7 +476,7 @@ func (r *StateStore) getKeyVersion(vals []interface{}) (data string, version *st seenData = true case "version": versionVal, _ := strconv.Unquote(fmt.Sprintf("%q", vals[i+1])) - version = ptr.String(versionVal) + version = ptr.Of(versionVal) seenVersion = true } } diff --git a/state/redis/redis_test.go b/state/redis/redis_test.go index fc99bd7a4..c90eeca17 100644 --- a/state/redis/redis_test.go +++ b/state/redis/redis_test.go @@ -19,7 +19,6 @@ import ( "testing" "time" - "github.com/agrea/ptr" miniredis "github.com/alicebob/miniredis/v2" redis "github.com/go-redis/redis/v8" jsoniter "github.com/json-iterator/go" @@ -28,6 +27,7 @@ import ( rediscomponent "github.com/dapr/components-contrib/internal/component/redis" "github.com/dapr/components-contrib/state" "github.com/dapr/kit/logger" + "github.com/dapr/kit/ptr" ) func TestGetKeyVersion(t *testing.T) { @@ -36,7 +36,7 @@ func TestGetKeyVersion(t *testing.T) { key, ver, err := store.getKeyVersion([]interface{}{"data", "TEST_KEY", "version", "TEST_VER"}) assert.Equal(t, nil, err, "failed to read all fields") assert.Equal(t, "TEST_KEY", key, "failed to read key") - assert.Equal(t, ptr.String("TEST_VER"), ver, "failed to read version") + assert.Equal(t, ptr.Of("TEST_VER"), ver, "failed to read version") }) t.Run("With missing data", func(t *testing.T) { _, _, err := store.getKeyVersion([]interface{}{"version", "TEST_VER"}) @@ -50,7 +50,7 @@ func TestGetKeyVersion(t *testing.T) { key, ver, err := store.getKeyVersion([]interface{}{"version", "TEST_VER", "dragon", "TEST_DRAGON", "data", "TEST_KEY"}) assert.Equal(t, nil, err, "failed to read all fields") assert.Equal(t, "TEST_KEY", key, "failed to read key") - assert.Equal(t, ptr.String("TEST_VER"), ver, "failed to read version") + assert.Equal(t, ptr.Of("TEST_VER"), ver, "failed to read version") }) t.Run("With no fields", func(t *testing.T) { _, _, err := store.getKeyVersion([]interface{}{}) @@ -245,7 +245,7 @@ func TestTransactionalUpsert(t *testing.T) { vals := res.([]interface{}) data, version, err := ss.getKeyVersion(vals) assert.Equal(t, nil, err) - assert.Equal(t, ptr.String("1"), version) + assert.Equal(t, ptr.Of("1"), version) assert.Equal(t, `"deathstar"`, data) res, err = c.Do(context.Background(), "TTL", "weapon").Result() @@ -394,7 +394,7 @@ func TestRequestsWithGlobalTTL(t *testing.T) { vals := res.([]interface{}) data, version, err := ss.getKeyVersion(vals) assert.Equal(t, nil, err) - assert.Equal(t, ptr.String("1"), version) + assert.Equal(t, ptr.Of("1"), version) assert.Equal(t, `"deathstar"`, data) res, err = c.Do(context.Background(), "TTL", "weapon").Result() diff --git a/state/rethinkdb/rethinkdb.go b/state/rethinkdb/rethinkdb.go index 9a43389b4..6db3044b8 100644 --- a/state/rethinkdb/rethinkdb.go +++ b/state/rethinkdb/rethinkdb.go @@ -20,12 +20,12 @@ import ( "strings" "time" - "github.com/agrea/ptr" r "github.com/dancannon/gorethink" "github.com/pkg/errors" "github.com/dapr/components-contrib/state" "github.com/dapr/kit/logger" + "github.com/dapr/kit/ptr" ) const ( @@ -171,7 +171,7 @@ func (s *RethinkDB) Get(req *state.GetRequest) (*state.GetResponse, error) { return nil, errors.Wrap(err, "error parsing database content") } - resp := &state.GetResponse{ETag: ptr.String(doc.Hash)} + resp := &state.GetResponse{ETag: ptr.Of(doc.Hash)} b, ok := doc.Data.([]byte) if ok { resp.Data = b diff --git a/state/sqlserver/sqlserver.go b/state/sqlserver/sqlserver.go index 7caeff835..1bddd3a8f 100644 --- a/state/sqlserver/sqlserver.go +++ b/state/sqlserver/sqlserver.go @@ -22,12 +22,12 @@ import ( "strconv" "unicode" - "github.com/agrea/ptr" mssql "github.com/denisenkom/go-mssqldb" "github.com/dapr/components-contrib/state" "github.com/dapr/components-contrib/state/utils" "github.com/dapr/kit/logger" + "github.com/dapr/kit/ptr" ) // KeyType defines type of the table identifier. @@ -540,7 +540,7 @@ func (s *SQLServer) Get(req *state.GetRequest) (*state.GetResponse, error) { return &state.GetResponse{ Data: []byte(data), - ETag: ptr.String(etag), + ETag: ptr.Of(etag), }, nil } diff --git a/state/zookeeper/zk.go b/state/zookeeper/zk.go index 3914f0c26..8cb0ebf60 100644 --- a/state/zookeeper/zk.go +++ b/state/zookeeper/zk.go @@ -20,13 +20,13 @@ import ( "strings" "time" - "github.com/agrea/ptr" "github.com/hashicorp/go-multierror" jsoniter "github.com/json-iterator/go" "github.com/samuel/go-zookeeper/zk" "github.com/dapr/components-contrib/state" "github.com/dapr/kit/logger" + "github.com/dapr/kit/ptr" ) const ( @@ -173,7 +173,7 @@ func (s *StateStore) Get(req *state.GetRequest) (*state.GetResponse, error) { return &state.GetResponse{ Data: value, - ETag: ptr.String(strconv.Itoa(int(stat.Version))), + ETag: ptr.Of(strconv.Itoa(int(stat.Version))), }, nil } diff --git a/state/zookeeper/zk_test.go b/state/zookeeper/zk_test.go index d25226db7..1a3077824 100644 --- a/state/zookeeper/zk_test.go +++ b/state/zookeeper/zk_test.go @@ -18,13 +18,13 @@ import ( "testing" "time" - "github.com/agrea/ptr" gomock "github.com/golang/mock/gomock" "github.com/hashicorp/go-multierror" "github.com/samuel/go-zookeeper/zk" "github.com/stretchr/testify/assert" "github.com/dapr/components-contrib/state" + "github.com/dapr/kit/ptr" ) //go:generate mockgen -package zookeeper -source zk.go -destination zk_mock.go @@ -83,7 +83,7 @@ func TestGet(t *testing.T) { res, err := s.Get(&state.GetRequest{Key: "foo"}) assert.NotNil(t, res, "Key must be exists") assert.Equal(t, "bar", string(res.Data), "Value must be equals") - assert.Equal(t, ptr.String("123"), res.ETag, "ETag must be equals") + assert.Equal(t, ptr.Of("123"), res.ETag, "ETag must be equals") assert.NoError(t, err, "Key must be exists") }) diff --git a/tests/certification/state/azure/blobstorage/go.mod b/tests/certification/state/azure/blobstorage/go.mod index afd11f81c..9109348cc 100644 --- a/tests/certification/state/azure/blobstorage/go.mod +++ b/tests/certification/state/azure/blobstorage/go.mod @@ -31,7 +31,6 @@ require ( github.com/Azure/go-autorest/tracing v0.6.0 // indirect github.com/AzureAD/microsoft-authentication-library-for-go v0.5.1 // indirect github.com/PuerkitoBio/purell v1.2.0 // indirect - github.com/agrea/ptr v0.0.0-20180711073057-77a518d99b7b // indirect github.com/andybalholm/brotli v1.0.4 // indirect github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220418222510-f25a4f6275ed // indirect github.com/armon/go-metrics v0.4.1 // indirect diff --git a/tests/certification/state/azure/blobstorage/go.sum b/tests/certification/state/azure/blobstorage/go.sum index bdb59ddd5..46df2c8f8 100644 --- a/tests/certification/state/azure/blobstorage/go.sum +++ b/tests/certification/state/azure/blobstorage/go.sum @@ -96,7 +96,6 @@ github.com/PuerkitoBio/purell v1.2.0 h1:/Jdm5QfyM8zdlqT6WVZU4cfP23sot6CEHA4CS49E github.com/PuerkitoBio/purell v1.2.0/go.mod h1:OhLRTaaIzhvIyofkJfB24gokC7tM42Px5UhoT32THBk= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/agrea/ptr v0.0.0-20180711073057-77a518d99b7b h1:WMhlIaJkDgEQSVJQM06YV+cYUl1r5OY5//ijMXJNqtA= -github.com/agrea/ptr v0.0.0-20180711073057-77a518d99b7b/go.mod h1:Tie46d3UWzXpj+Fh9+DQTyaUxEpFBPOLXrnx7nxlKRo= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= diff --git a/tests/certification/state/mongodb/go.mod b/tests/certification/state/mongodb/go.mod index d026b36e1..eb2839cf1 100644 --- a/tests/certification/state/mongodb/go.mod +++ b/tests/certification/state/mongodb/go.mod @@ -15,7 +15,6 @@ require ( contrib.go.opencensus.io/exporter/prometheus v0.4.2 // indirect github.com/AdhityaRamadhanus/fasthttpcors v0.0.0-20170121111917-d4c07198763a // indirect github.com/PuerkitoBio/purell v1.2.0 // indirect - github.com/agrea/ptr v0.0.0-20180711073057-77a518d99b7b // indirect github.com/andybalholm/brotli v1.0.4 // indirect github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220418222510-f25a4f6275ed // indirect github.com/armon/go-metrics v0.4.1 // indirect diff --git a/tests/certification/state/mongodb/go.sum b/tests/certification/state/mongodb/go.sum index 2210233f9..bd26f9a1f 100644 --- a/tests/certification/state/mongodb/go.sum +++ b/tests/certification/state/mongodb/go.sum @@ -44,7 +44,6 @@ github.com/PuerkitoBio/purell v1.2.0 h1:/Jdm5QfyM8zdlqT6WVZU4cfP23sot6CEHA4CS49E github.com/PuerkitoBio/purell v1.2.0/go.mod h1:OhLRTaaIzhvIyofkJfB24gokC7tM42Px5UhoT32THBk= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/agrea/ptr v0.0.0-20180711073057-77a518d99b7b h1:WMhlIaJkDgEQSVJQM06YV+cYUl1r5OY5//ijMXJNqtA= -github.com/agrea/ptr v0.0.0-20180711073057-77a518d99b7b/go.mod h1:Tie46d3UWzXpj+Fh9+DQTyaUxEpFBPOLXrnx7nxlKRo= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= diff --git a/tests/certification/state/postgresql/go.mod b/tests/certification/state/postgresql/go.mod index 181bdcf50..3c5255b8b 100644 --- a/tests/certification/state/postgresql/go.mod +++ b/tests/certification/state/postgresql/go.mod @@ -15,7 +15,6 @@ require ( contrib.go.opencensus.io/exporter/prometheus v0.4.2 // indirect github.com/AdhityaRamadhanus/fasthttpcors v0.0.0-20170121111917-d4c07198763a // indirect github.com/PuerkitoBio/purell v1.2.0 // indirect - github.com/agrea/ptr v0.0.0-20180711073057-77a518d99b7b // indirect github.com/andybalholm/brotli v1.0.4 // indirect github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220418222510-f25a4f6275ed // indirect github.com/armon/go-metrics v0.4.1 // indirect diff --git a/tests/certification/state/postgresql/go.sum b/tests/certification/state/postgresql/go.sum index 896f5f48c..f30ac73a9 100644 --- a/tests/certification/state/postgresql/go.sum +++ b/tests/certification/state/postgresql/go.sum @@ -45,7 +45,6 @@ github.com/PuerkitoBio/purell v1.2.0 h1:/Jdm5QfyM8zdlqT6WVZU4cfP23sot6CEHA4CS49E github.com/PuerkitoBio/purell v1.2.0/go.mod h1:OhLRTaaIzhvIyofkJfB24gokC7tM42Px5UhoT32THBk= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/agrea/ptr v0.0.0-20180711073057-77a518d99b7b h1:WMhlIaJkDgEQSVJQM06YV+cYUl1r5OY5//ijMXJNqtA= -github.com/agrea/ptr v0.0.0-20180711073057-77a518d99b7b/go.mod h1:Tie46d3UWzXpj+Fh9+DQTyaUxEpFBPOLXrnx7nxlKRo= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= diff --git a/tests/certification/state/redis/go.mod b/tests/certification/state/redis/go.mod index da1120963..1d941ed95 100644 --- a/tests/certification/state/redis/go.mod +++ b/tests/certification/state/redis/go.mod @@ -17,7 +17,6 @@ require ( contrib.go.opencensus.io/exporter/prometheus v0.4.2 // indirect github.com/AdhityaRamadhanus/fasthttpcors v0.0.0-20170121111917-d4c07198763a // indirect github.com/PuerkitoBio/purell v1.2.0 // indirect - github.com/agrea/ptr v0.0.0-20180711073057-77a518d99b7b // indirect github.com/andybalholm/brotli v1.0.4 // indirect github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220418222510-f25a4f6275ed // indirect github.com/armon/go-metrics v0.4.1 // indirect diff --git a/tests/certification/state/redis/go.sum b/tests/certification/state/redis/go.sum index 150473901..f9e4d82bd 100644 --- a/tests/certification/state/redis/go.sum +++ b/tests/certification/state/redis/go.sum @@ -44,7 +44,6 @@ github.com/PuerkitoBio/purell v1.2.0 h1:/Jdm5QfyM8zdlqT6WVZU4cfP23sot6CEHA4CS49E github.com/PuerkitoBio/purell v1.2.0/go.mod h1:OhLRTaaIzhvIyofkJfB24gokC7tM42Px5UhoT32THBk= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/agrea/ptr v0.0.0-20180711073057-77a518d99b7b h1:WMhlIaJkDgEQSVJQM06YV+cYUl1r5OY5//ijMXJNqtA= -github.com/agrea/ptr v0.0.0-20180711073057-77a518d99b7b/go.mod h1:Tie46d3UWzXpj+Fh9+DQTyaUxEpFBPOLXrnx7nxlKRo= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= diff --git a/tests/certification/state/sqlserver/go.mod b/tests/certification/state/sqlserver/go.mod index 4c7f1513f..7a073440e 100644 --- a/tests/certification/state/sqlserver/go.mod +++ b/tests/certification/state/sqlserver/go.mod @@ -15,7 +15,6 @@ require ( contrib.go.opencensus.io/exporter/prometheus v0.4.2 // indirect github.com/AdhityaRamadhanus/fasthttpcors v0.0.0-20170121111917-d4c07198763a // indirect github.com/PuerkitoBio/purell v1.2.0 // indirect - github.com/agrea/ptr v0.0.0-20180711073057-77a518d99b7b // indirect github.com/andybalholm/brotli v1.0.4 // indirect github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220418222510-f25a4f6275ed // indirect github.com/armon/go-metrics v0.4.1 // indirect diff --git a/tests/certification/state/sqlserver/go.sum b/tests/certification/state/sqlserver/go.sum index fde5ee6cb..6d2742716 100644 --- a/tests/certification/state/sqlserver/go.sum +++ b/tests/certification/state/sqlserver/go.sum @@ -47,7 +47,6 @@ github.com/PuerkitoBio/purell v1.2.0 h1:/Jdm5QfyM8zdlqT6WVZU4cfP23sot6CEHA4CS49E github.com/PuerkitoBio/purell v1.2.0/go.mod h1:OhLRTaaIzhvIyofkJfB24gokC7tM42Px5UhoT32THBk= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/agrea/ptr v0.0.0-20180711073057-77a518d99b7b h1:WMhlIaJkDgEQSVJQM06YV+cYUl1r5OY5//ijMXJNqtA= -github.com/agrea/ptr v0.0.0-20180711073057-77a518d99b7b/go.mod h1:Tie46d3UWzXpj+Fh9+DQTyaUxEpFBPOLXrnx7nxlKRo= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=