diff --git a/.golangci.yml b/.golangci.yml index efaf32e7e..955af06d6 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -225,66 +225,27 @@ linters-settings: # Default: false checkExported: true linters: - disable-all: true - enable: -# - cyclop + enable-all: true + disable: + - godot + - varnamelen + - wrapcheck + - nosnakecase + - deadcode + - golint + - interfacer + - maligned + - ifshort + - structcheck + - exhaustivestruct + - scopelint + - varcheck + - ireturn - depguard - - dogsled -# - dupl - - errcheck - - errorlint -# - exhaustive -# - exhaustivestruct -# - forbidigo -# - funlen -# - gci -# - gocognit - - goconst - - gocritic - - gocyclo -# - godot - - godox - - gofmt # On why gofmt when goimports is enabled - https://github.com/golang/go/issues/21476 - - gofumpt - - goheader - - goimports -# - gomnd -# - gomoddirectives -# - gomodguard - - gosec - - gosimple - - govet - - depguard -# - ifshort -# - ireturn - - lll - - makezero - - misspell - - ineffassign - - misspell - - nakedret - - nestif -# - nilnil -# - nlreturn - - nolintlint - - prealloc - - predeclared - - rowserrcheck - - revive - - staticcheck - - stylecheck -# - tagliatelle -# - testpackage -# - thelper -# - tenv - - typecheck - - unconvert - - unparam - - unused -# - varnamelen - - whitespace -# - wrapcheck -# - wsl + - wsl + - exhaustruct + - gci + - paralleltest #need be enabled issues: # List of regexps of issue texts to exclude, empty list by default. diff --git a/connection.go b/connection.go index df33f42d8..3e8e3d2a4 100644 --- a/connection.go +++ b/connection.go @@ -16,6 +16,8 @@ import ( // Interface and list of clients may be changed in the future // // Deprecated: use directly *Driver type from ydb.Open instead +// +//nolint:interfacebloat type Connection interface { // Endpoint returns initial endpoint Endpoint() string diff --git a/driver.go b/driver.go index 69c96873a..800fc3afc 100644 --- a/driver.go +++ b/driver.go @@ -97,10 +97,13 @@ func (d *Driver) trace() *trace.Driver { if d.config != nil { return d.config.Trace() } + return &trace.Driver{} } // Close closes Driver and clear resources +// +//nolint:nonamedreturns func (d *Driver) Close(ctx context.Context) (finalErr error) { onDone := trace.DriverOnClose(d.trace(), &ctx, stack.FunctionID("")) defer func() { @@ -207,6 +210,8 @@ func (d *Driver) Topic() topic.Client { // "grpc[s]://{endpoint}/{database}[?param=value]" // // See sugar.DSN helper for make dsn from endpoint and database +// +//nolint:nonamedreturns func Open(ctx context.Context, dsn string, opts ...Option) (_ *Driver, err error) { d, err := newConnectionFromOptions(ctx, append( []Option{ @@ -239,12 +244,15 @@ func MustOpen(ctx context.Context, dsn string, opts ...Option) *Driver { if err != nil { panic(err) } + return db } // New connects to database and return driver runtime holder // // Deprecated: use Open with required param connectionString instead +// +//nolint:nonamedreturns func New(ctx context.Context, opts ...Option) (_ *Driver, err error) { d, err := newConnectionFromOptions(ctx, opts...) if err != nil { @@ -267,6 +275,7 @@ func New(ctx context.Context, opts ...Option) (_ *Driver, err error) { return d, nil } +//nolint:cyclop, nonamedreturns func newConnectionFromOptions(ctx context.Context, opts ...Option) (_ *Driver, err error) { d := &Driver{ children: make(map[uint64]*Driver), @@ -304,16 +313,16 @@ func newConnectionFromOptions(ctx context.Context, opts ...Option) (_ *Driver, e } if d.logger != nil { for _, opt := range []Option{ - WithTraceDriver(log.Driver(d.logger, d.loggerDetails, d.loggerOpts...)), - WithTraceTable(log.Table(d.logger, d.loggerDetails, d.loggerOpts...)), - WithTraceScripting(log.Scripting(d.logger, d.loggerDetails, d.loggerOpts...)), + WithTraceDriver(log.Driver(d.logger, d.loggerDetails, d.loggerOpts...)), //nolint:contextcheck + WithTraceTable(log.Table(d.logger, d.loggerDetails, d.loggerOpts...)), //nolint:contextcheck + WithTraceScripting(log.Scripting(d.logger, d.loggerDetails, d.loggerOpts...)), //nolint:contextcheck WithTraceScheme(log.Scheme(d.logger, d.loggerDetails, d.loggerOpts...)), WithTraceCoordination(log.Coordination(d.logger, d.loggerDetails, d.loggerOpts...)), WithTraceRatelimiter(log.Ratelimiter(d.logger, d.loggerDetails, d.loggerOpts...)), - WithTraceDiscovery(log.Discovery(d.logger, d.loggerDetails, d.loggerOpts...)), - WithTraceTopic(log.Topic(d.logger, d.loggerDetails, d.loggerOpts...)), - WithTraceDatabaseSQL(log.DatabaseSQL(d.logger, d.loggerDetails, d.loggerOpts...)), - WithTraceRetry(log.Retry(d.logger, d.loggerDetails, d.loggerOpts...)), + WithTraceDiscovery(log.Discovery(d.logger, d.loggerDetails, d.loggerOpts...)), //nolint:contextcheck + WithTraceTopic(log.Topic(d.logger, d.loggerDetails, d.loggerOpts...)), //nolint:contextcheck + WithTraceDatabaseSQL(log.DatabaseSQL(d.logger, d.loggerDetails, d.loggerOpts...)), //nolint:contextcheck + WithTraceRetry(log.Retry(d.logger, d.loggerDetails, d.loggerOpts...)), //nolint:contextcheck } { if opt != nil { err = opt(ctx, d) @@ -324,16 +333,18 @@ func newConnectionFromOptions(ctx context.Context, opts ...Option) (_ *Driver, e } } d.config = config.New(d.options...) + return d, nil } +//nolint:cyclop, nonamedreturns, funlen func (d *Driver) connect(ctx context.Context) (err error) { if d.config.Endpoint() == "" { - return xerrors.WithStackTrace(errors.New("configuration: empty dial address")) + return xerrors.WithStackTrace(errors.New("configuration: empty dial address")) //nolint:goerr113 } if d.config.Database() == "" { - return xerrors.WithStackTrace(errors.New("configuration: empty database")) + return xerrors.WithStackTrace(errors.New("configuration: empty database")) //nolint:goerr113 } if d.userInfo != nil { diff --git a/errors.go b/errors.go index 944ae86a7..55027bef0 100644 --- a/errors.go +++ b/errors.go @@ -83,6 +83,8 @@ func IsOperationErrorSchemeError(err error) bool { } // IsOperationErrorTransactionLocksInvalidated checks does err a TLI issue +// +//nolint:nonamedreturns func IsOperationErrorTransactionLocksInvalidated(err error) (isTLI bool) { return xerrors.IsOperationErrorTransactionLocksInvalidated(err) } diff --git a/example_test.go b/example_test.go index 542a6571a..3b06248e6 100644 --- a/example_test.go +++ b/example_test.go @@ -21,6 +21,7 @@ import ( "github.com/ydb-platform/ydb-go-sdk/v3/topic/topicoptions" ) +//nolint:testableexamples, nonamedreturns func Example_table() { ctx := context.TODO() db, err := ydb.Open(ctx, "grpc://localhost:2136/local") @@ -54,6 +55,7 @@ func Example_table() { } log.Printf("id=%v, myStr='%s'\n", id, myStr) } + return res.Err() // return finally result error for auto-retry with driver }, table.WithIdempotent(), @@ -63,6 +65,7 @@ func Example_table() { } } +//nolint:testableexamples func Example_databaseSQL() { db, err := sql.Open("ydb", "grpc://localhost:2136/local") if err != nil { @@ -85,6 +88,7 @@ func Example_databaseSQL() { return err } log.Printf("id=%v, myStr='%s'\n", id, myStr) + return nil }, retry.WithIdempotent(true)) if err != nil { @@ -92,6 +96,7 @@ func Example_databaseSQL() { } } +//nolint:testableexamples func Example_databaseSQLBindNumericArgs() { db, err := sql.Open("ydb", "grpc://localhost:2136/local?go_query_bind=declare,numeric", @@ -115,6 +120,7 @@ func Example_databaseSQLBindNumericArgs() { } } +//nolint:testableexamples func Example_databaseSQLBindNumericArgsOverConnector() { var ( ctx = context.TODO() @@ -146,6 +152,7 @@ func Example_databaseSQLBindNumericArgsOverConnector() { } } +//nolint:testableexamples func Example_databaseSQLBindPositionalArgs() { db, err := sql.Open("ydb", "grpc://localhost:2136/local?go_query_bind=declare,positional", @@ -169,6 +176,7 @@ func Example_databaseSQLBindPositionalArgs() { } } +//nolint:testableexamples func Example_databaseSQLBindPositionalArgsOverConnector() { var ( ctx = context.TODO() @@ -197,6 +205,7 @@ func Example_databaseSQLBindPositionalArgsOverConnector() { } } +//nolint:testableexamples func Example_databaseSQLBindTablePathPrefix() { db, err := sql.Open("ydb", "grpc://localhost:2136/local?go_query_bind=table_path_prefix(/local/path/to/tables)", @@ -220,6 +229,7 @@ func Example_databaseSQLBindTablePathPrefix() { } } +//nolint:testableexamples func Example_databaseSQLBindTablePathPrefixOverConnector() { var ( ctx = context.TODO() @@ -243,6 +253,7 @@ func Example_databaseSQLBindTablePathPrefixOverConnector() { } } +//nolint:testableexamples func Example_databaseSQLBindAutoDeclare() { db, err := sql.Open("ydb", "grpc://localhost:2136/local?go_query_bind=declare", @@ -268,6 +279,7 @@ func Example_databaseSQLBindAutoDeclare() { } } +//nolint:testableexamples func Example_databaseSQLBindAutoDeclareOverConnector() { var ( ctx = context.TODO() @@ -293,11 +305,13 @@ func Example_databaseSQLBindAutoDeclareOverConnector() { } } +//nolint:testableexamples func Example_topic() { ctx := context.TODO() db, err := ydb.Open(ctx, "grpc://localhost:2136/local") if err != nil { fmt.Printf("failed connect: %v", err) + return } defer db.Close(ctx) // cleanup resources @@ -305,6 +319,7 @@ func Example_topic() { reader, err := db.Topic().StartReader("consumer", topicoptions.ReadTopic("/topic/path")) if err != nil { fmt.Printf("failed start reader: %v", err) + return } @@ -312,27 +327,31 @@ func Example_topic() { mess, err := reader.ReadMessage(ctx) if err != nil { fmt.Printf("failed start reader: %v", err) + return } content, err := io.ReadAll(mess) if err != nil { fmt.Printf("failed start reader: %v", err) + return } fmt.Println(string(content)) } } +//nolint:testableexamples func Example_scripting() { ctx := context.TODO() db, err := ydb.Open(ctx, "grpc://localhost:2136/local") if err != nil { fmt.Printf("failed to connect: %v", err) + return } - defer db.Close(ctx) // cleanup resources - if err = retry.Retry(ctx, func(ctx context.Context) (err error) { + defer db.Close(ctx) // cleanup resources + if err = retry.Retry(ctx, func(ctx context.Context) (err error) { //nolint:nonamedreturns res, err := db.Scripting().Execute( ctx, "SELECT 1+1", @@ -344,13 +363,13 @@ func Example_scripting() { defer res.Close() // cleanup resources if !res.NextResultSet(ctx) { return retry.RetryableError( - fmt.Errorf("no result sets"), + fmt.Errorf("no result sets"), //nolint:goerr113 retry.WithBackoff(retry.TypeNoBackoff), ) } if !res.NextRow() { return retry.RetryableError( - fmt.Errorf("no rows"), + fmt.Errorf("no rows"), //nolint:goerr113 retry.WithBackoff(retry.TypeSlowBackoff), ) } @@ -359,25 +378,29 @@ func Example_scripting() { return fmt.Errorf("scan failed: %w", err) } if sum != 2 { - return fmt.Errorf("unexpected sum: %v", sum) + return fmt.Errorf("unexpected sum: %v", sum) //nolint:goerr113 } + return res.Err() }, retry.WithIdempotent(true)); err != nil { fmt.Printf("Execute failed: %v", err) } } +//nolint:testableexamples func Example_discovery() { ctx := context.TODO() db, err := ydb.Open(ctx, "grpc://localhost:2136/local") if err != nil { fmt.Printf("failed to connect: %v", err) + return } defer db.Close(ctx) // cleanup resources endpoints, err := db.Discovery().Discover(ctx) if err != nil { fmt.Printf("discover failed: %v", err) + return } fmt.Printf("%s endpoints:\n", db.Name()) @@ -386,6 +409,7 @@ func Example_discovery() { } } +//nolint:testableexamples func Example_enableGzipCompressionForAllRequests() { ctx := context.TODO() db, err := ydb.Open( @@ -405,6 +429,7 @@ func Example_enableGzipCompressionForAllRequests() { fmt.Printf("connected to %s, database '%s'", db.Endpoint(), db.Name()) } +//nolint:testableexamples func ExampleOpen() { ctx := context.TODO() db, err := ydb.Open(ctx, "grpc://localhost:2135/local") @@ -415,6 +440,7 @@ func ExampleOpen() { fmt.Printf("connected to %s, database '%s'", db.Endpoint(), db.Name()) } +//nolint:testableexamples func ExampleOpen_advanced() { ctx := context.TODO() db, err := ydb.Open( diff --git a/options.go b/options.go index c6e14cfa9..41c995f97 100644 --- a/options.go +++ b/options.go @@ -37,6 +37,7 @@ func WithStaticCredentials(user, password string) Option { User: user, Password: password, } + return nil } } @@ -56,6 +57,7 @@ func WithAccessTokenCredentials(accessToken string) Option { func WithUserAgent(userAgent string) Option { return func(ctx context.Context, c *Driver) error { c.options = append(c.options, config.WithUserAgent(userAgent)) + return nil } } @@ -63,6 +65,7 @@ func WithUserAgent(userAgent string) Option { func WithRequestsType(requestsType string) Option { return func(ctx context.Context, c *Driver) error { c.options = append(c.options, config.WithRequestsType(requestsType)) + return nil } } @@ -87,6 +90,7 @@ func WithConnectionString(connectionString string) Option { } c.options = append(c.options, info.Options...) c.userInfo = info.UserInfo + return nil } } @@ -95,6 +99,7 @@ func WithConnectionString(connectionString string) Option { func WithConnectionTTL(ttl time.Duration) Option { return func(ctx context.Context, c *Driver) error { c.options = append(c.options, config.WithConnectionTTL(ttl)) + return nil } } @@ -107,6 +112,7 @@ func WithConnectionTTL(ttl time.Duration) Option { func WithEndpoint(endpoint string) Option { return func(ctx context.Context, c *Driver) error { c.options = append(c.options, config.WithEndpoint(endpoint)) + return nil } } @@ -119,6 +125,7 @@ func WithEndpoint(endpoint string) Option { func WithDatabase(database string) Option { return func(ctx context.Context, c *Driver) error { c.options = append(c.options, config.WithDatabase(database)) + return nil } } @@ -131,6 +138,7 @@ func WithDatabase(database string) Option { func WithSecure(secure bool) Option { return func(ctx context.Context, c *Driver) error { c.options = append(c.options, config.WithSecure(secure)) + return nil } } @@ -141,6 +149,7 @@ func WithSecure(secure bool) Option { func WithInsecure() Option { return func(ctx context.Context, c *Driver) error { c.options = append(c.options, config.WithSecure(false)) + return nil } } @@ -149,6 +158,7 @@ func WithInsecure() Option { func WithMinTLSVersion(minVersion uint16) Option { return func(ctx context.Context, c *Driver) error { c.options = append(c.options, config.WithMinTLSVersion(minVersion)) + return nil } } @@ -157,6 +167,7 @@ func WithMinTLSVersion(minVersion uint16) Option { func WithTLSSInsecureSkipVerify() Option { return func(ctx context.Context, c *Driver) error { c.options = append(c.options, config.WithTLSSInsecureSkipVerify()) + return nil } } @@ -169,6 +180,7 @@ func WithLogger(l log.Logger, details trace.Detailer, opts ...log.Option) Option c.logger = l c.loggerOpts = opts c.loggerDetails = details + return nil } } @@ -188,6 +200,7 @@ func WithCreateCredentialsFunc(createCredentials func(ctx context.Context) (cred return xerrors.WithStackTrace(err) } c.options = append(c.options, config.WithCredentials(creds)) + return nil } } @@ -203,6 +216,7 @@ func WithCredentials(c credentials.Credentials) Option { func WithBalancer(balancer *balancerConfig.Config) Option { return func(ctx context.Context, c *Driver) error { c.options = append(c.options, config.WithBalancer(balancer)) + return nil } } @@ -213,6 +227,7 @@ func WithBalancer(balancer *balancerConfig.Config) Option { func WithDialTimeout(timeout time.Duration) Option { return func(ctx context.Context, c *Driver) error { c.options = append(c.options, config.WithDialTimeout(timeout)) + return nil } } @@ -223,6 +238,7 @@ func WithDialTimeout(timeout time.Duration) Option { func With(options ...config.Option) Option { return func(ctx context.Context, c *Driver) error { c.options = append(c.options, options...) + return nil } } @@ -237,6 +253,7 @@ func MergeOptions(opts ...Option) Option { } } } + return nil } } @@ -245,6 +262,7 @@ func MergeOptions(opts ...Option) Option { func WithDiscoveryInterval(discoveryInterval time.Duration) Option { return func(ctx context.Context, c *Driver) error { c.discoveryOptions = append(c.discoveryOptions, discoveryConfig.WithInterval(discoveryInterval)) + return nil } } @@ -253,6 +271,7 @@ func WithDiscoveryInterval(discoveryInterval time.Duration) Option { func WithTraceDriver(t trace.Driver, opts ...trace.DriverComposeOption) Option { //nolint:gocritic return func(ctx context.Context, c *Driver) error { c.options = append(c.options, config.WithTrace(t, opts...)) + return nil } } @@ -268,6 +287,7 @@ func WithTraceRetry(t trace.Retry, opts ...trace.RetryComposeOption) Option { opts..., )...), ) + return nil } } @@ -276,6 +296,7 @@ func WithTraceRetry(t trace.Retry, opts ...trace.RetryComposeOption) Option { func WithCertificate(cert *x509.Certificate) Option { return func(ctx context.Context, c *Driver) error { c.options = append(c.options, config.WithCertificate(cert)) + return nil } } @@ -293,6 +314,7 @@ func WithCertificatesFromFile(caFile string, opts ...certificates.FromFileOption if file, err := filepath.EvalSymlinks(caFile); err == nil { caFile = file } + return func(ctx context.Context, c *Driver) error { certs, err := certificates.FromFile(caFile, opts...) if err != nil { @@ -303,6 +325,7 @@ func WithCertificatesFromFile(caFile string, opts ...certificates.FromFileOption return xerrors.WithStackTrace(err) } } + return nil } } @@ -314,6 +337,7 @@ func WithCertificatesFromFile(caFile string, opts ...certificates.FromFileOption func WithTLSConfig(tlsConfig *tls.Config) Option { return func(ctx context.Context, c *Driver) error { c.options = append(c.options, config.WithTLSConfig(tlsConfig)) + return nil } } @@ -328,6 +352,7 @@ func WithCertificatesFromPem(bytes []byte, opts ...certificates.FromPemOption) O for _, cert := range certs { _ = WithCertificate(cert)(ctx, c) } + return nil } } @@ -337,6 +362,7 @@ func WithCertificatesFromPem(bytes []byte, opts ...certificates.FromPemOption) O func WithTableConfigOption(option tableConfig.Option) Option { return func(ctx context.Context, c *Driver) error { c.tableOptions = append(c.tableOptions, option) + return nil } } @@ -345,6 +371,7 @@ func WithTableConfigOption(option tableConfig.Option) Option { func WithSessionPoolSizeLimit(sizeLimit int) Option { return func(ctx context.Context, c *Driver) error { c.tableOptions = append(c.tableOptions, tableConfig.WithSizeLimit(sizeLimit)) + return nil } } @@ -364,6 +391,7 @@ func WithSessionPoolIdleThreshold(idleThreshold time.Duration) Option { c.databaseSQLOptions, xsql.WithIdleThreshold(idleThreshold), ) + return nil } } @@ -377,6 +405,7 @@ func WithSessionPoolKeepAliveTimeout(keepAliveTimeout time.Duration) Option { func WithSessionPoolCreateSessionTimeout(createSessionTimeout time.Duration) Option { return func(ctx context.Context, c *Driver) error { c.tableOptions = append(c.tableOptions, tableConfig.WithCreateSessionTimeout(createSessionTimeout)) + return nil } } @@ -385,6 +414,7 @@ func WithSessionPoolCreateSessionTimeout(createSessionTimeout time.Duration) Opt func WithSessionPoolDeleteTimeout(deleteTimeout time.Duration) Option { return func(ctx context.Context, c *Driver) error { c.tableOptions = append(c.tableOptions, tableConfig.WithDeleteTimeout(deleteTimeout)) + return nil } } @@ -393,6 +423,7 @@ func WithSessionPoolDeleteTimeout(deleteTimeout time.Duration) Option { func WithIgnoreTruncated() Option { return func(ctx context.Context, c *Driver) error { c.tableOptions = append(c.tableOptions, tableConfig.WithIgnoreTruncated()) + return nil } } @@ -405,6 +436,7 @@ func WithPanicCallback(panicCallback func(e interface{})) Option { return func(ctx context.Context, c *Driver) error { c.panicCallback = panicCallback c.options = append(c.options, config.WithPanicCallback(panicCallback)) + return nil } } @@ -424,6 +456,7 @@ func WithTraceTable(t trace.Table, opts ...trace.TableComposeOption) Option { // )..., ), ) + return nil } } @@ -443,6 +476,7 @@ func WithTraceScripting(t trace.Scripting, opts ...trace.ScriptingComposeOption) )..., ), ) + return nil } } @@ -462,6 +496,7 @@ func WithTraceScheme(t trace.Scheme, opts ...trace.SchemeComposeOption) Option { )..., ), ) + return nil } } @@ -481,6 +516,7 @@ func WithTraceCoordination(t trace.Coordination, opts ...trace.CoordinationCompo )..., ), ) + return nil } } @@ -500,6 +536,7 @@ func WithTraceRatelimiter(t trace.Ratelimiter, opts ...trace.RatelimiterComposeO )..., ), ) + return nil } } @@ -508,6 +545,7 @@ func WithTraceRatelimiter(t trace.Ratelimiter, opts ...trace.RatelimiterComposeO func WithRatelimiterOptions(opts ...ratelimiterConfig.Option) Option { return func(ctx context.Context, c *Driver) error { c.ratelimiterOptions = append(c.ratelimiterOptions, opts...) + return nil } } @@ -527,6 +565,7 @@ func WithTraceDiscovery(t trace.Discovery, opts ...trace.DiscoveryComposeOption) )..., ), ) + return nil } } @@ -546,6 +585,7 @@ func WithTraceTopic(t trace.Topic, opts ...trace.TopicComposeOption) Option { // )..., ), ) + return nil } } @@ -565,6 +605,7 @@ func WithTraceDatabaseSQL(t trace.DatabaseSQL, opts ...trace.DatabaseSQLComposeO )..., ), ) + return nil } } @@ -574,6 +615,7 @@ func WithTraceDatabaseSQL(t trace.DatabaseSQL, opts ...trace.DatabaseSQLComposeO func withOnClose(onClose func(c *Driver)) Option { return func(ctx context.Context, c *Driver) error { c.onClose = append(c.onClose, onClose) + return nil } } @@ -581,6 +623,7 @@ func withOnClose(onClose func(c *Driver)) Option { func withConnPool(pool *conn.Pool) Option { return func(ctx context.Context, c *Driver) error { c.pool = pool + return pool.Take(ctx) } } diff --git a/query_bind_test.go b/query_bind_test.go index 905aa5975..24870c0c9 100644 --- a/query_bind_test.go +++ b/query_bind_test.go @@ -14,6 +14,7 @@ import ( "github.com/ydb-platform/ydb-go-sdk/v3/testutil" ) +//nolint:funlen, maintidx func TestQueryBind(t *testing.T) { now := time.Now() for _, tt := range []struct { diff --git a/sql.go b/sql.go index eac5314ed..0db01dd72 100644 --- a/sql.go +++ b/sql.go @@ -15,9 +15,9 @@ import ( "github.com/ydb-platform/ydb-go-sdk/v3/trace" ) -var d = &sqlDriver{connectors: make(map[*xsql.Connector]*Driver)} +var d = &sqlDriver{connectors: make(map[*xsql.Connector]*Driver)} //nolint:gochecknoglobals -func init() { +func init() { //nolint:gochecknoinits sql.Register("ydb", d) sql.Register("ydb/v3", d) } @@ -46,6 +46,7 @@ func (d *sqlDriver) Close() error { if len(errs) > 0 { return xerrors.NewWithIssues("ydb legacy driver close failed", errs...) } + return nil } @@ -63,6 +64,7 @@ func (d *sqlDriver) OpenConnector(dataSourceName string) (driver.Connector, erro if err != nil { return nil, xerrors.WithStackTrace(fmt.Errorf("failed to connect by data source name '%s': %w", dataSourceName, err)) } + return Connector(db, connectorOpts...) } @@ -171,6 +173,7 @@ func Connector(parent *Driver, opts ...ConnectorOption) (SQLConnector, error) { return nil, xerrors.WithStackTrace(err) } d.attach(c, parent) + return c, nil } @@ -179,5 +182,6 @@ func MustConnector(parent *Driver, opts ...ConnectorOption) SQLConnector { if err != nil { panic(err) } + return c } diff --git a/sql_unwrap.go b/sql_unwrap.go index d72eff8f9..8fd07e1f8 100644 --- a/sql_unwrap.go +++ b/sql_unwrap.go @@ -17,5 +17,6 @@ func Unwrap(db *sql.DB) (*Driver, error) { } d.connectorsMtx.RLock() defer d.connectorsMtx.RUnlock() + return d.connectors[c], nil } diff --git a/sql_unwrap_go1.18.go b/sql_unwrap_go1.18.go index 0fdd60da1..b5ea788c0 100644 --- a/sql_unwrap_go1.18.go +++ b/sql_unwrap_go1.18.go @@ -17,5 +17,6 @@ func Unwrap[T *sql.DB | *sql.Conn](v T) (*Driver, error) { } d.connectorsMtx.RLock() defer d.connectorsMtx.RUnlock() + return d.connectors[c], nil } diff --git a/with.go b/with.go index 300d65cac..f8a39d594 100644 --- a/with.go +++ b/with.go @@ -9,7 +9,7 @@ import ( "github.com/ydb-platform/ydb-go-sdk/v3/trace" ) -var nextID xatomic.Uint64 +var nextID xatomic.Uint64 //nolint:gochecknoglobals func (d *Driver) with(ctx context.Context, opts ...Option) (*Driver, uint64, error) { id := nextID.Add(1) @@ -36,6 +36,7 @@ func (d *Driver) with(ctx context.Context, opts ...Option) (*Driver, uint64, err if err != nil { return nil, 0, xerrors.WithStackTrace(err) } + return child, id, nil } diff --git a/with_test.go b/with_test.go index 5469a45ed..a6152fed3 100644 --- a/with_test.go +++ b/with_test.go @@ -1,4 +1,4 @@ -package ydb +package ydb //nolint:testpackage import ( "bytes" @@ -21,7 +21,7 @@ import ( "github.com/ydb-platform/ydb-go-sdk/v3/internal/conn" ) -func TestWithCertificatesCached(t *testing.T) { +func TestWithCertificatesCached(t *testing.T) { //nolint:funlen ca := &x509.Certificate{ SerialNumber: big.NewInt(2019), Subject: pkix.Name{ @@ -61,7 +61,6 @@ func TestWithCertificatesCached(t *testing.T) { missCounter uint64 ctx = context.TODO() ) - for _, test := range []struct { name string options []Option @@ -132,7 +131,7 @@ func TestWithCertificatesCached(t *testing.T) { db, err := newConnectionFromOptions(ctx, append( test.options, - withConnPool(conn.NewPool(context.Background(), config.New())), + withConnPool(conn.NewPool(context.Background(), config.New())), //nolint:contextcheck )..., ) require.NoError(t, err)