Updated depguard linter config (#2245)
* 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>
This commit is contained in:
parent
132b22ecf2
commit
ca3e80b76b
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
1
go.mod
1
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
|
||||
|
|
2
go.sum
2
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=
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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")
|
||||
})
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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=
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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=
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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=
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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=
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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=
|
||||
|
|
Loading…
Reference in New Issue