From e7a7718bca5d020fff18bc79cccbe3dd970b53b5 Mon Sep 17 00:00:00 2001 From: Aleksey Myasnikov <79263256394.ya@gmail.com> Date: Fri, 19 May 2023 15:13:07 +0300 Subject: [PATCH] improve gocritic linter and fix --- .gitignore | 4 +- .golangci.yml | 101 +++++- CHANGELOG.md | 2 + config/config.go | 36 +- config/defaults.go | 4 +- connection.go | 2 +- credentials/credentials.go | 2 +- examples/basic/database_sql/data.go | 14 +- examples/basic/database_sql/series.go | 2 +- examples/basic/gorm/main.go | 20 +- examples/basic/gorm/models.go | 8 +- examples/basic/native/series.go | 46 ++- examples/ddl/ddl.go | 2 +- examples/describe/main.go | 8 +- examples/read_table/orders.go | 2 +- examples/serverless/healthcheck/service.go | 12 +- examples/serverless/url_shortener/service.go | 14 +- .../topic/cdc-cache-bus-freeseats/cache.go | 2 +- .../cdc-cache-bus-freeseats/webserver.go | 1 + .../cdc-cache-bus-freeseats/webserver_cdc.go | 1 + examples/topic/topicreader/stubs.go | 2 +- examples/ttl_readtable/series.go | 4 +- internal/balancer/balancer.go | 10 +- internal/balancer/connections_state.go | 2 +- internal/balancer/local_dc.go | 2 +- internal/cmd/gtrace/main.go | 21 +- internal/cmd/gtrace/writer.go | 66 ++-- internal/conn/conn.go | 8 +- internal/credentials/access_token.go | 2 +- internal/credentials/static.go | 2 +- internal/discovery/config/config.go | 22 +- internal/discovery/discovery.go | 4 +- internal/endpoint/endpoint.go | 2 +- internal/grpcwrapper/rawtopic/client.go | 4 +- internal/meta/meta.go | 10 +- internal/scheme/helpers/check_exists.go | 16 +- internal/table/client.go | 14 +- internal/table/client_test.go | 4 +- internal/table/config/config.go | 28 +- internal/table/data_query.go | 2 +- internal/table/retry.go | 14 +- internal/table/retry_test.go | 12 +- internal/table/scanner/scanner.go | 25 +- internal/table/session.go | 4 +- internal/topic/topicclientinternal/client.go | 8 +- internal/topic/topicreaderinternal/batch.go | 6 +- .../topicreaderinternal/partition_session.go | 13 +- internal/topic/topicreaderinternal/reader.go | 26 +- .../topicreaderinternal/stream_reader_impl.go | 40 +-- .../stream_reader_impl_test.go | 4 +- internal/topic/topicwriterinternal/message.go | 15 +- internal/topic/topicwriterinternal/queue.go | 10 +- .../topicwriterinternal/writer_reconnector.go | 14 +- .../writer_reconnector_test.go | 6 +- .../writer_single_stream.go | 6 +- .../writer_single_stream_test.go | 4 +- internal/value/type.go | 18 +- internal/value/value.go | 48 +-- internal/wait/wait.go | 2 +- internal/xerrors/operation.go | 2 +- internal/xresolver/xresolver.go | 6 +- internal/xsql/conn.go | 38 +-- internal/xsql/connector.go | 4 +- internal/xsql/dsn_test.go | 2 +- internal/xsql/rows.go | 4 +- internal/xsync/mutex.go | 4 +- internal/xtest/manytimes.go | 8 +- log/field.go | 27 +- log/join.go | 9 +- log/logger.go | 4 +- log/topic.go | 71 ++-- options.go | 10 +- retry/retry.go | 4 +- sql.go | 7 +- sugar/path.go | 8 +- table/options/options.go | 10 +- table/result/named/named.go | 41 ++- table/table.go | 2 +- tests/slo/internal/metrics/metrics.go | 4 +- testutil/compare.go | 68 ++-- topic/topicoptions/topicoptions_reader.go | 4 +- topic/topicoptions/topicoptions_topic.go | 2 +- topic/topicoptions/topicoptions_writer.go | 4 +- trace/topic.go | 63 ++-- trace/topic_gtrace.go | 310 +++++++++--------- 85 files changed, 835 insertions(+), 664 deletions(-) diff --git a/.gitignore b/.gitignore index cbc991617..8e4c4d9e7 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,6 @@ *.out vendor changes.txt -./internal/cmd/gtrace/gtrace \ No newline at end of file +./internal/cmd/gtrace/gtrace +examples/.golangci.yml +tests/slo/.golangci.yml \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml index 1426dbf71..4cb946822 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -125,7 +125,105 @@ linters-settings: # if it's called for subdir of a project it can't find external interfaces. All text editor integrations # with golangci-lint call it on a directory with the changed file. check-exported: false - + gocritic: + disabled-checks: + - whyNoLint # https://github.com/go-critic/go-critic/issues/1063 + - importShadow + - sloppyReassign +# - typeDefFirst + # Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks. + # See https://github.com/go-critic/go-critic#usage -> section "Tags". + # Default: [] + enabled-tags: + - diagnostic + - style + - performance + - experimental + - opinionated + # Settings passed to gocritic. + # The settings key is the name of a supported gocritic checker. + # The list of supported checkers can be find in https://go-critic.github.io/overview. + settings: + # Must be valid enabled check name. + captLocal: + # Whether to restrict checker to params only. + # Default: true + paramsOnly: false + elseif: + # Whether to skip balanced if-else pairs. + # Default: true + skipBalanced: false + hugeParam: + # Size in bytes that makes the warning trigger. + # Default: 80 + sizeThreshold: 70 + nestingReduce: + # Min number of statements inside a branch to trigger a warning. + # Default: 5 + bodyWidth: 4 + rangeExprCopy: + # Size in bytes that makes the warning trigger. + # Default: 512 + sizeThreshold: 516 + # Whether to check test functions + # Default: true + skipTestFuncs: false + rangeValCopy: + # Size in bytes that makes the warning trigger. + # Default: 128 + sizeThreshold: 32 + # Whether to check test functions. + # Default: true + skipTestFuncs: false + ruleguard: + # Enable debug to identify which 'Where' condition was rejected. + # The value of the parameter is the name of a function in a ruleguard file. + # + # When a rule is evaluated: + # If: + # The Match() clause is accepted; and + # One of the conditions in the Where() clause is rejected, + # Then: + # ruleguard prints the specific Where() condition that was rejected. + # + # The flag is passed to the ruleguard 'debug-group' argument. + # Default: "" + debug: 'emptyDecl' + # Deprecated, use 'failOn' param. + # If set to true, identical to failOn='all', otherwise failOn='' + failOnError: false + # Determines the behavior when an error occurs while parsing ruleguard files. + # If flag is not set, log error and skip rule files that contain an error. + # If flag is set, the value must be a comma-separated list of error conditions. + # - 'all': fail on all errors. + # - 'import': ruleguard rule imports a package that cannot be found. + # - 'dsl': gorule file does not comply with the ruleguard DSL. + # Default: "" + failOn: dsl + # Comma-separated list of enabled groups or skip empty to enable everything. + # Tags can be defined with # character prefix. + # Default: "" + enable: "myGroupName,#myTagName" + # Comma-separated list of disabled groups or skip empty to enable everything. + # Tags can be defined with # character prefix. + # Default: "" + disable: "myGroupName,#myTagName" + tooManyResultsChecker: + # Maximum number of results. + # Default: 5 + maxResults: 10 + truncateCmp: + # Whether to skip int/uint/uintptr types. + # Default: true + skipArchDependent: false + underef: + # Whether to skip (*x).method() calls where x is a pointer receiver. + # Default: true + skipRecvDeref: false + unnamedResult: + # Whether to check exported functions. + # Default: false + checkExported: true linters: disable-all: true enable: @@ -238,5 +336,6 @@ issues: linters: - unused - unparam + - gocritic - path: _test\.go text: "ydb.Connection is deprecated" diff --git a/CHANGELOG.md b/CHANGELOG.md index 799405c1e..bd783e54e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +* Improved code with `go-critic` linter + ## v3.47.3 * Added `table/options.Description.Tiering` field diff --git a/config/config.go b/config/config.go index f8589d3d9..20dc44bb6 100644 --- a/config/config.go +++ b/config/config.go @@ -30,22 +30,22 @@ type Config struct { grpcOptions []grpc.DialOption credentials credentials.Credentials tlsConfig *tls.Config - meta meta.Meta + meta *meta.Meta excludeGRPCCodesForPessimization []grpcCodes.Code } -func (c Config) Credentials() credentials.Credentials { +func (c *Config) Credentials() credentials.Credentials { return c.credentials } // ExcludeGRPCCodesForPessimization defines grpc codes for exclude its from pessimization trigger -func (c Config) ExcludeGRPCCodesForPessimization() []grpcCodes.Code { +func (c *Config) ExcludeGRPCCodesForPessimization() []grpcCodes.Code { return c.excludeGRPCCodesForPessimization } // GrpcDialOptions reports about used grpc dialing options -func (c Config) GrpcDialOptions() []grpc.DialOption { +func (c *Config) GrpcDialOptions() []grpc.DialOption { return append( defaultGrpcOptions(c.trace, c.secure, c.tlsConfig), c.grpcOptions..., @@ -53,29 +53,29 @@ func (c Config) GrpcDialOptions() []grpc.DialOption { } // Meta reports meta information about database connection -func (c Config) Meta() meta.Meta { +func (c *Config) Meta() *meta.Meta { return c.meta } // ConnectionTTL defines interval for parking grpc connections. // // If ConnectionTTL is zero - connections are not park. -func (c Config) ConnectionTTL() time.Duration { +func (c *Config) ConnectionTTL() time.Duration { return c.connectionTTL } // Secure is a flag for secure connection -func (c Config) Secure() bool { +func (c *Config) Secure() bool { return c.secure } // Endpoint is a required starting endpoint for connect -func (c Config) Endpoint() string { +func (c *Config) Endpoint() string { return c.endpoint } // TLSConfig reports about TLS configuration -func (c Config) TLSConfig() *tls.Config { +func (c *Config) TLSConfig() *tls.Config { return c.tlsConfig } @@ -83,23 +83,23 @@ func (c Config) TLSConfig() *tls.Config { // complete. // // If DialTimeout is zero then no timeout is used. -func (c Config) DialTimeout() time.Duration { +func (c *Config) DialTimeout() time.Duration { return c.dialTimeout } // Database is a required database name. -func (c Config) Database() string { +func (c *Config) Database() string { return c.database } // Trace contains driver tracing options. -func (c Config) Trace() *trace.Driver { +func (c *Config) Trace() *trace.Driver { return c.trace } // Balancer is an optional configuration related to selected balancer. // That is, some balancing methods allow to be configured. -func (c Config) Balancer() *balancerConfig.Config { +func (c *Config) Balancer() *balancerConfig.Config { return c.balancerConfig } @@ -149,7 +149,7 @@ func WithTLSConfig(tlsConfig *tls.Config) Option { } } -func WithTrace(t trace.Driver, opts ...trace.DriverComposeOption) Option { +func WithTrace(t trace.Driver, opts ...trace.DriverComposeOption) Option { //nolint:gocritic return func(c *Config) { c.trace = c.trace.Compose(&t, opts...) } @@ -259,12 +259,12 @@ func ExcludeGRPCCodesForPessimization(codes ...grpcCodes.Code) Option { } } -func New(opts ...Option) Config { +func New(opts ...Option) *Config { c := defaultConfig() for _, o := range opts { if o != nil { - o(&c) + o(c) } } @@ -274,10 +274,10 @@ func New(opts ...Option) Config { } // With makes copy of current Config with specified options -func (c Config) With(opts ...Option) Config { +func (c *Config) With(opts ...Option) *Config { for _, o := range opts { if o != nil { - o(&c) + o(c) } } c.meta = meta.New( diff --git a/config/defaults.go b/config/defaults.go index 6dca0b5cd..5b5ddb668 100644 --- a/config/defaults.go +++ b/config/defaults.go @@ -81,8 +81,8 @@ func defaultTLSConfig() *tls.Config { } } -func defaultConfig() (c Config) { - return Config{ +func defaultConfig() (c *Config) { + return &Config{ credentials: credentials.NewAnonymousCredentials( credentials.WithSourceInfo("default"), ), diff --git a/connection.go b/connection.go index 4f7a28ef3..adea4994d 100644 --- a/connection.go +++ b/connection.go @@ -93,7 +93,7 @@ type Driver struct { //nolint:maligned opts []Option - config config.Config + config *config.Config options []config.Option discoveryOnce initOnce diff --git a/credentials/credentials.go b/credentials/credentials.go index bb044c14c..c677e5858 100644 --- a/credentials/credentials.go +++ b/credentials/credentials.go @@ -56,6 +56,6 @@ func NewAnonymousCredentials(opts ...option) Credentials { } // NewStaticCredentials makes static credentials object -func NewStaticCredentials(user, password string, authEndpoint string, opts ...grpc.DialOption) Credentials { +func NewStaticCredentials(user, password, authEndpoint string, opts ...grpc.DialOption) Credentials { return credentials.NewStaticCredentials(user, password, authEndpoint, opts...) } diff --git a/examples/basic/database_sql/data.go b/examples/basic/database_sql/data.go index 36024d822..279c895be 100644 --- a/examples/basic/database_sql/data.go +++ b/examples/basic/database_sql/data.go @@ -28,7 +28,7 @@ func seriesData(id string, released time.Time, title, info, comment string) type ) } -func seasonData(seriesID, seasonID string, title string, first, last time.Time) types.Value { +func seasonData(seriesID, seasonID, title string, first, last time.Time) types.Value { return types.StructValue( types.StructFieldValue("series_id", types.BytesValueFromString(seriesID)), types.StructFieldValue("season_id", types.BytesValueFromString(seasonID)), @@ -38,7 +38,7 @@ func seasonData(seriesID, seasonID string, title string, first, last time.Time) ) } -func episodeData(seriesID, seasonID, episodeID string, title string, date time.Time) types.Value { +func episodeData(seriesID, seasonID, episodeID, title string, date time.Time) types.Value { return types.StructValue( types.StructFieldValue("series_id", types.BytesValueFromString(seriesID)), types.StructFieldValue("season_id", types.BytesValueFromString(seasonID)), @@ -48,7 +48,7 @@ func episodeData(seriesID, seasonID, episodeID string, title string, date time.T ) } -func getData() (series []types.Value, seasons []types.Value, episodes []types.Value) { +func getData() (series, seasons, episodes []types.Value) { for seriesID, fill := range map[string]func(seriesID string) ( seriesData types.Value, seasons []types.Value, episodes []types.Value, ){ @@ -63,14 +63,14 @@ func getData() (series []types.Value, seasons []types.Value, episodes []types.Va return } -func getDataForITCrowd(seriesID string) (series types.Value, seasons []types.Value, episodes []types.Value) { +func getDataForITCrowd(seriesID string) (series types.Value, seasons, episodes []types.Value) { series = seriesData( seriesID, date("2006-02-03"), "IT Crowd", ""+ "The IT Crowd is a British sitcom produced by Channel 4, written by Graham Linehan, produced by "+ "Ash Atalla and starring Chris O'Dowd, Richard Ayoade, Katherine Parkinson, and Matt Berry.", "", // NULL comment. ) - for _, season := range []struct { + for _, season := range []struct { //nolint:gocritic title string first time.Time last time.Time @@ -118,14 +118,14 @@ func getDataForITCrowd(seriesID string) (series types.Value, seasons []types.Val return series, seasons, episodes } -func getDataForSiliconValley(seriesID string) (series types.Value, seasons []types.Value, episodes []types.Value) { +func getDataForSiliconValley(seriesID string) (series types.Value, seasons, episodes []types.Value) { series = seriesData( seriesID, date("2014-04-06"), "Silicon Valley", ""+ "Silicon Valley is an American comedy television series created by Mike Judge, John Altschuler and "+ "Dave Krinsky. The series focuses on five young men who founded a startup company in Silicon Valley.", "Some comment here", ) - for _, season := range []struct { + for _, season := range []struct { //nolint:gocritic title string first time.Time last time.Time diff --git a/examples/basic/database_sql/series.go b/examples/basic/database_sql/series.go index e275e7a67..348c62567 100644 --- a/examples/basic/database_sql/series.go +++ b/examples/basic/database_sql/series.go @@ -37,7 +37,7 @@ func selectDefault(ctx context.Context, db *sql.DB) (err error) { if err = row.Scan(&ast, &plan); err != nil { return err } - // log.Printf("AST = %s\n\nPlan = %s", ast, plan) + log.Printf("AST = %s\n\nPlan = %s", ast, plan) return nil }, retry.WithDoRetryOptions(retry.WithIdempotent(true))) if err != nil { diff --git a/examples/basic/gorm/main.go b/examples/basic/gorm/main.go index af71a6b1b..6affba9e0 100644 --- a/examples/basic/gorm/main.go +++ b/examples/basic/gorm/main.go @@ -103,20 +103,22 @@ func readAll(db *gorm.DB) error { return err } log.Println("all known series:") - for _, s := range series { + for i := range series { log.Printf( " > [%s] %s (%s)\n", - s.ID, s.Title, s.ReleaseDate.Format("2006"), + series[i].ID, series[i].Title, series[i].ReleaseDate.Format("2006"), ) - for _, ss := range s.Seasons { + for j := range series[i].Seasons { log.Printf( " > [%s] %s\n", - ss.ID, ss.Title, + series[i].Seasons[j].ID, series[i].Seasons[j].Title, ) - for _, e := range ss.Episodes { + for k := range series[i].Seasons[j].Episodes { log.Printf( " > [%s] [%s] %s\n", - e.ID, e.AirDate.Format(dateISO8601), e.Title, + series[i].Seasons[j].Episodes[k].ID, + series[i].Seasons[j].Episodes[k].AirDate.Format(dateISO8601), + series[i].Seasons[j].Episodes[k].Title, ) } } @@ -133,9 +135,9 @@ func findEpisodesByTitle(db *gorm.DB, fragment string) error { return err } log.Println("all episodes with title with word 'bad':") - for _, e := range episodes { + for i := range episodes { ss := Season{ - ID: e.SeasonID, + ID: episodes[i].SeasonID, } if err := db.Take(&ss).Error; err != nil { return err @@ -156,7 +158,7 @@ func findEpisodesByTitle(db *gorm.DB, fragment string) error { ) log.Printf( " > [%s] [%s] %s\n", - e.ID, e.AirDate.Format(dateISO8601), e.Title, + episodes[i].ID, episodes[i].AirDate.Format(dateISO8601), episodes[i].Title, ) } return nil diff --git a/examples/basic/gorm/models.go b/examples/basic/gorm/models.go index d6936f2f1..c96edc7ee 100644 --- a/examples/basic/gorm/models.go +++ b/examples/basic/gorm/models.go @@ -23,8 +23,8 @@ func (s *Series) BeforeCreate(_ *gorm.DB) (err error) { return err } s.ID = id.String() - for _, season := range s.Seasons { - season.SeriesID = s.ID + for i := range s.Seasons { + s.Seasons[i].SeriesID = s.ID } return } @@ -45,8 +45,8 @@ func (s *Season) BeforeCreate(_ *gorm.DB) (err error) { return err } s.ID = id.String() - for _, episode := range s.Episodes { - episode.SeasonID = s.ID + for i := range s.Episodes { + s.Episodes[i].SeasonID = s.ID } return } diff --git a/examples/basic/native/series.go b/examples/basic/native/series.go index e7a47e9f0..a9e267aab 100644 --- a/examples/basic/native/series.go +++ b/examples/basic/native/series.go @@ -150,26 +150,40 @@ func describeTableOptions(ctx context.Context, c table.Client) (err error) { } log.Println("> describe_table_options:") - for i, p := range desc.TableProfilePresets { - log.Printf("TableProfilePresets: %d/%d: %+v", i+1, len(desc.TableProfilePresets), p) + for i := range desc.TableProfilePresets { + log.Printf("TableProfilePresets: %d/%d: %+v", i+1, + len(desc.TableProfilePresets), desc.TableProfilePresets[i], + ) } - for i, p := range desc.StoragePolicyPresets { - log.Printf("StoragePolicyPresets: %d/%d: %+v", i+1, len(desc.StoragePolicyPresets), p) + for i := range desc.StoragePolicyPresets { + log.Printf("StoragePolicyPresets: %d/%d: %+v", i+1, + len(desc.StoragePolicyPresets), desc.StoragePolicyPresets[i], + ) } - for i, p := range desc.CompactionPolicyPresets { - log.Printf("CompactionPolicyPresets: %d/%d: %+v", i+1, len(desc.CompactionPolicyPresets), p) + for i := range desc.CompactionPolicyPresets { + log.Printf("CompactionPolicyPresets: %d/%d: %+v", i+1, + len(desc.CompactionPolicyPresets), desc.CompactionPolicyPresets[i], + ) } - for i, p := range desc.PartitioningPolicyPresets { - log.Printf("PartitioningPolicyPresets: %d/%d: %+v", i+1, len(desc.PartitioningPolicyPresets), p) + for i := range desc.PartitioningPolicyPresets { + log.Printf("PartitioningPolicyPresets: %d/%d: %+v", i+1, + len(desc.PartitioningPolicyPresets), desc.PartitioningPolicyPresets[i], + ) } - for i, p := range desc.ExecutionPolicyPresets { - log.Printf("ExecutionPolicyPresets: %d/%d: %+v", i+1, len(desc.ExecutionPolicyPresets), p) + for i := range desc.ExecutionPolicyPresets { + log.Printf("ExecutionPolicyPresets: %d/%d: %+v", i+1, + len(desc.ExecutionPolicyPresets), desc.ExecutionPolicyPresets[i], + ) } - for i, p := range desc.ReplicationPolicyPresets { - log.Printf("ReplicationPolicyPresets: %d/%d: %+v", i+1, len(desc.ReplicationPolicyPresets), p) + for i := range desc.ReplicationPolicyPresets { + log.Printf("ReplicationPolicyPresets: %d/%d: %+v", i+1, + len(desc.ReplicationPolicyPresets), desc.ReplicationPolicyPresets[i], + ) } - for i, p := range desc.CachingPolicyPresets { - log.Printf("CachingPolicyPresets: %d/%d: %+v", i+1, len(desc.CachingPolicyPresets), p) + for i := range desc.CachingPolicyPresets { + log.Printf("CachingPolicyPresets: %d/%d: %+v", i+1, + len(desc.CachingPolicyPresets), desc.CachingPolicyPresets[i], + ) } return nil @@ -390,8 +404,8 @@ func describeTable(ctx context.Context, c table.Client, path string) (err error) return err } log.Printf("> describe table: %s", path) - for _, c := range desc.Columns { - log.Printf("column, name: %s, %s", c.Type, c.Name) + for i := range desc.Columns { + log.Printf("column, name: %s, %s", desc.Columns[i].Type, desc.Columns[i].Name) } return nil }, diff --git a/examples/ddl/ddl.go b/examples/ddl/ddl.go index 30f1fd2a3..6641c913f 100644 --- a/examples/ddl/ddl.go +++ b/examples/ddl/ddl.go @@ -67,7 +67,7 @@ ALTER TABLE small_table3 SET (TTL = Interval("PT3H") ON d); ` ) -func executeQuery(ctx context.Context, c table.Client, prefix string, query string) (err error) { +func executeQuery(ctx context.Context, c table.Client, prefix, query string) (err error) { err = c.Do(ctx, func(ctx context.Context, s table.Session) error { err = s.ExecuteSchemeQuery(ctx, fmt.Sprintf(query, prefix)) diff --git a/examples/describe/main.go b/examples/describe/main.go index a1ab1d979..cc8f7106c 100644 --- a/examples/describe/main.go +++ b/examples/describe/main.go @@ -109,11 +109,11 @@ func list(ctx context.Context, db *ydb.Driver, t *template.Template, p string) { return } - for _, child := range dir.Children { - pt := path.Join(p, child.Name) - switch child.Type { + for i := range dir.Children { + pt := path.Join(p, dir.Children[i].Name) + switch dir.Children[i].Type { case scheme.EntryDirectory, scheme.EntryDatabase: - if _, ok := ignoreDirs[child.Name]; ok { + if _, ok := ignoreDirs[dir.Children[i].Name]; ok { continue } list(ctx, db, t, pt) diff --git a/examples/read_table/orders.go b/examples/read_table/orders.go index 8eb4f361f..7255608ef 100644 --- a/examples/read_table/orders.go +++ b/examples/read_table/orders.go @@ -121,7 +121,7 @@ func fillTable(ctx context.Context, c table.Client, prefix string) (err error) { ) } -func order(customerID uint64, orderID uint64, description string, date string) types.Value { +func order(customerID, orderID uint64, description, date string) types.Value { orderDate, err := time.Parse(dateLayout, date) if err != nil { panic(err) diff --git a/examples/serverless/healthcheck/service.go b/examples/serverless/healthcheck/service.go index 455297df0..60df561f5 100644 --- a/examples/serverless/healthcheck/service.go +++ b/examples/serverless/healthcheck/service.go @@ -59,7 +59,7 @@ func getService(ctx context.Context, dsn string, opts ...ydb.Option) (s *service } func (s *service) Close(ctx context.Context) { - defer func() { _ = s.db.Close(ctx) }() + _ = s.db.Close(ctx) } func (s *service) createTableIfNotExists(ctx context.Context) error { @@ -98,7 +98,7 @@ func (s *service) ping(path string) (code int32, err error) { if uri.Scheme == "" { uri.Scheme = "http" } - request, err := http.NewRequest(http.MethodGet, uri.String(), nil) + request, err := http.NewRequest(http.MethodGet, uri.String(), nil) //nolint:gocritic if err != nil { return -1, err } @@ -148,17 +148,17 @@ func (s *service) check(ctx context.Context, urls []string) error { func (s *service) upsertRows(ctx context.Context, rows []row) (err error) { values := make([]types.Value, len(rows)) - for i, row := range rows { + for i := range rows { values[i] = types.StructValue( - types.StructFieldValue("url", types.TextValue(row.url)), - types.StructFieldValue("code", types.Int32Value(row.code)), + types.StructFieldValue("url", types.TextValue(rows[i].url)), + types.StructFieldValue("code", types.Int32Value(rows[i].code)), types.StructFieldValue("ts", types.DatetimeValueFromTime(time.Now())), types.StructFieldValue("error", types.TextValue(func(err error) string { if err != nil { return err.Error() } return "" - }(row.err))), + }(rows[i].err))), ) } err = s.db.Table().Do(ctx, diff --git a/examples/serverless/url_shortener/service.go b/examples/serverless/url_shortener/service.go index 9fb9f139a..9d56a6139 100644 --- a/examples/serverless/url_shortener/service.go +++ b/examples/serverless/url_shortener/service.go @@ -33,12 +33,6 @@ import ( "github.com/ydb-platform/ydb-go-sdk/v3/trace" ) -const ( - invalidHashError = "'%s' is not a valid short path." - hashNotFound = "hash '%s' is not found" - invalidURLError = "'%s' is not a valid URL." -) - //go:embed static/index.html var static embed.FS @@ -182,7 +176,7 @@ func getService(ctx context.Context, dsn string, opts ...ydb.Option) (s *service } func (s *service) Close(ctx context.Context) { - defer func() { _ = s.db.Close(ctx) }() + _ = s.db.Close(ctx) } func (s *service) createTable(ctx context.Context) (err error) { @@ -302,7 +296,7 @@ func (s *service) selectLong(ctx context.Context, hash string) (url string, err return src, err } } - return "", fmt.Errorf(hashNotFound, hash) + return "", fmt.Errorf("hash '%s' is not found", hash) } func writeResponse(w http.ResponseWriter, statusCode int, body string) { @@ -382,7 +376,7 @@ func (s *service) handleShorten(w http.ResponseWriter, r *http.Request) { return } if !isLongCorrect(string(url)) { - err = fmt.Errorf(fmt.Sprintf(invalidURLError, url)) + err = fmt.Errorf("'%s' is not a valid URL", url) writeResponse(w, http.StatusBadRequest, err.Error()) return } @@ -418,7 +412,7 @@ func (s *service) handleLonger(w http.ResponseWriter, r *http.Request) { }() path := strings.Split(r.URL.Path, "/") if !isShortCorrect(path[len(path)-1]) { - err = fmt.Errorf(fmt.Sprintf(invalidHashError, path[len(path)-1])) + err = fmt.Errorf("'%s' is not a valid short path", path[len(path)-1]) writeResponse(w, http.StatusBadRequest, err.Error()) return } diff --git a/examples/topic/cdc-cache-bus-freeseats/cache.go b/examples/topic/cdc-cache-bus-freeseats/cache.go index f68c23fd1..ada1aac22 100644 --- a/examples/topic/cdc-cache-bus-freeseats/cache.go +++ b/examples/topic/cdc-cache-bus-freeseats/cache.go @@ -76,7 +76,7 @@ func (c *Cache) set(now time.Time, key string, value int64) { } func (c *Cache) cleanupNeedLock(now time.Time) { - for key, item := range c.values { + for key, item := range c.values { //nolint:gocritic if now.After(item.ExpiresAt) { delete(c.values, key) } diff --git a/examples/topic/cdc-cache-bus-freeseats/webserver.go b/examples/topic/cdc-cache-bus-freeseats/webserver.go index bee2b450f..790339b53 100644 --- a/examples/topic/cdc-cache-bus-freeseats/webserver.go +++ b/examples/topic/cdc-cache-bus-freeseats/webserver.go @@ -75,6 +75,7 @@ func (s *server) BuyTicketHandler(writer http.ResponseWriter, request *http.Requ } return } + //nolint:gocritic // s.cache.Delete(id) // used without cdc, for single-instance application duration := time.Since(start) s.writeAnswer(writer, freeSeats, duration) diff --git a/examples/topic/cdc-cache-bus-freeseats/webserver_cdc.go b/examples/topic/cdc-cache-bus-freeseats/webserver_cdc.go index 06ab66524..70f4a1f22 100644 --- a/examples/topic/cdc-cache-bus-freeseats/webserver_cdc.go +++ b/examples/topic/cdc-cache-bus-freeseats/webserver_cdc.go @@ -44,6 +44,7 @@ func (s *server) cdcLoop() { } busID := cdcEvent.Key[0] + //nolint:gocritic // s.dropFromCache(busID) // used for clean cache and force database request if cdcEvent.Erase == nil { s.cache.Set(busID, cdcEvent.Update.FreeSeats) // used for direct update cache from cdc without database request diff --git a/examples/topic/topicreader/stubs.go b/examples/topic/topicreader/stubs.go index 351b15434..ef64775a3 100644 --- a/examples/topic/topicreader/stubs.go +++ b/examples/topic/topicreader/stubs.go @@ -10,7 +10,7 @@ func getEndOffset(b *topicreader.Batch) int64 { panic("example stub") } -func externalSystemCommit(ctx context.Context, topic string, partition int64, offset int64) error { +func externalSystemCommit(ctx context.Context, topic string, partition, offset int64) error { panic("example stub") } diff --git a/examples/ttl_readtable/series.go b/examples/ttl_readtable/series.go index 14ccf37a1..cb6fb62ec 100644 --- a/examples/ttl_readtable/series.go +++ b/examples/ttl_readtable/series.go @@ -142,11 +142,11 @@ func deleteExpired(ctx context.Context, c table.Client, prefix string, timestamp if err != nil { return err } - for _, kr := range res.KeyRanges { + for i := range res.KeyRanges { // DeleteExpiredRange can be run in parallel for different ranges. // Keep in mind that deletion RPS should be somehow limited in this case to avoid // spikes of cluster load due to TTL. - err = deleteExpiredRange(ctx, c, prefix, timestamp, kr) + err = deleteExpiredRange(ctx, c, prefix, timestamp, res.KeyRanges[i]) if err != nil { return err } diff --git a/internal/balancer/balancer.go b/internal/balancer/balancer.go index 46139d4f3..e6e9060f1 100644 --- a/internal/balancer/balancer.go +++ b/internal/balancer/balancer.go @@ -31,7 +31,7 @@ type discoveryClient interface { } type Balancer struct { - driverConfig config.Config + driverConfig *config.Config balancerConfig balancerConfig.Config pool *conn.Pool discoveryClient discoveryClient @@ -176,7 +176,7 @@ func (b *Balancer) Close(ctx context.Context) (err error) { func New( ctx context.Context, - driverConfig config.Config, + driverConfig *config.Config, pool *conn.Pool, opts ...discoveryConfig.Option, ) (b *Balancer, err error) { @@ -276,10 +276,8 @@ func (b *Balancer) wrapCall(ctx context.Context, f func(ctx context.Context, cc if cc.GetState() == conn.Banned { b.pool.Allow(ctx, cc) } - } else { - if xerrors.MustPessimizeEndpoint(err, b.driverConfig.ExcludeGRPCCodesForPessimization()...) { - b.pool.Ban(ctx, cc, err) - } + } else if xerrors.MustPessimizeEndpoint(err, b.driverConfig.ExcludeGRPCCodesForPessimization()...) { + b.pool.Ban(ctx, cc, err) } }() diff --git a/internal/balancer/connections_state.go b/internal/balancer/connections_state.go index c7f344c9f..6a8d57981 100644 --- a/internal/balancer/connections_state.go +++ b/internal/balancer/connections_state.go @@ -134,7 +134,7 @@ func sortPreferConnections( preferFunc balancerConfig.PreferConnFunc, info balancerConfig.Info, allowFallback bool, -) (prefer []conn.Conn, fallback []conn.Conn) { +) (prefer, fallback []conn.Conn) { if preferFunc == nil { return conns, nil } diff --git a/internal/balancer/local_dc.go b/internal/balancer/local_dc.go index ac4db8b45..d375ac680 100644 --- a/internal/balancer/local_dc.go +++ b/internal/balancer/local_dc.go @@ -130,7 +130,7 @@ func detectLocalDC(ctx context.Context, endpoints []endpoint.Endpoint) (string, return "", err } -func extractHostPort(address string) (host string, port string, _ error) { +func extractHostPort(address string) (host, port string, _ error) { if !strings.Contains(address, "://") { address = "stub://" + address } diff --git a/internal/cmd/gtrace/main.go b/internal/cmd/gtrace/main.go index 1fab014fe..95a72f0c2 100644 --- a/internal/cmd/gtrace/main.go +++ b/internal/cmd/gtrace/main.go @@ -109,15 +109,14 @@ func main() { var file *os.File file, err = os.Open(filepath.Join(workDir, name)) if err != nil { - //nolint:gocritic - log.Fatal(err) + panic(err) } - defer file.Close() + defer file.Close() //nolint:gocritic var ast *ast.File ast, err = parser.ParseFile(fset, file.Name(), file, parser.ParseComments) if err != nil { - log.Fatalf("parse %q error: %v", file.Name(), err) + panic(fmt.Sprintf("parse %q error: %v", file.Name(), err)) } pkgFiles = append(pkgFiles, file) @@ -125,15 +124,15 @@ func main() { if name == gofile { if _, err = file.Seek(0, io.SeekStart); err != nil { - log.Fatal(err) + panic(err) } buildConstraints, err = scanBuildConstraints(file) if err != nil { - log.Fatal(err) + panic(err) } } } - info := types.Info{ + info := &types.Info{ Types: make(map[ast.Expr]types.TypeAndValue), Defs: make(map[*ast.Ident]types.Object), Uses: make(map[*ast.Ident]types.Object), @@ -143,9 +142,9 @@ func main() { DisableUnusedImportCheck: true, Importer: importer.ForCompiler(fset, "source", nil), } - pkg, err := conf.Check(".", fset, astFiles, &info) + pkg, err := conf.Check(".", fset, astFiles, info) if err != nil { - log.Fatalf("type error: %v", err) + panic(fmt.Sprintf("type error: %v", err)) } var items []*GenItem for i, astFile := range astFiles { @@ -239,14 +238,14 @@ func main() { } for _, w := range writers { if err := w.Write(p); err != nil { - log.Fatal(err) + panic(err) } } log.Println("OK") } -func buildFunc(info types.Info, traces map[string]*Trace, fn *ast.FuncType) (ret *Func, err error) { +func buildFunc(info *types.Info, traces map[string]*Trace, fn *ast.FuncType) (ret *Func, err error) { ret = new(Func) for _, p := range fn.Params.List { t := info.TypeOf(p.Type) diff --git a/internal/cmd/gtrace/writer.go b/internal/cmd/gtrace/writer.go index ff520a1c1..869909f18 100644 --- a/internal/cmd/gtrace/writer.go +++ b/internal/cmd/gtrace/writer.go @@ -179,9 +179,9 @@ func unwrapStruct(t types.Type) (n *types.Named, s *types.Struct) { } func (w *Writer) funcImports(dst []dep, fn *Func) []dep { - for _, p := range fn.Params { - dst = w.typeImports(dst, p.Type) - if _, s := unwrapStruct(p.Type); s != nil { + for i := range fn.Params { + dst = w.typeImports(dst, fn.Params[i].Type) + if _, s := unwrapStruct(fn.Params[i].Type); s != nil { forEachField(s, func(v *types.Var) { if v.Exported() { dst = w.typeImports(dst, v.Type()) @@ -234,14 +234,14 @@ func (w *Writer) importDeps(deps []dep) { }) w.line(`import (`) var lastStd bool - for _, d := range deps { - if w.isStdLib(d.pkgPath) { + for i := range deps { + if w.isStdLib(deps[i].pkgPath) { lastStd = true } else if lastStd { lastStd = false w.line() } - w.line("\t", `"`, d.pkgPath, `"`) + w.line("\t", `"`, deps[i].pkgPath, `"`) } w.line(`)`) w.line() @@ -460,11 +460,11 @@ func (w *Writer) hook(trace *Trace, hook Hook) { w.code(`(`) var args []string - for i, p := range hook.Func.Params { + for i := range hook.Func.Params { if i > 0 { w.code(`, `) } - args = append(args, w.funcParam(p)) + args = append(args, w.funcParam(&hook.Func.Params[i])) } w.code(`)`) if hook.Func.HasResult() { @@ -527,7 +527,7 @@ func (w *Writer) hookFuncCall(fn *Func, name string, args []string) { w.line(`return `, res) } -func nameParam(p Param) (s string) { +func nameParam(p *Param) (s string) { s = p.Name if s == "" { s = firstChar(ident(typeBasename(p.Type))) @@ -537,20 +537,20 @@ func nameParam(p Param) (s string) { func (w *Writer) declareParams(src []Param) (names []string) { names = make([]string, len(src)) - for i, p := range src { - names[i] = w.declare(nameParam(p)) + for i := range src { + names[i] = w.declare(nameParam(&src[i])) } return names } -func flattenParams(src []Param) (dst []Param) { - for _, p := range src { - _, s := unwrapStruct(p.Type) +func flattenParams(params []Param) (dst []Param) { + for i := range params { + _, s := unwrapStruct(params[i].Type) if s != nil { dst = flattenStruct(dst, s) continue } - dst = append(dst, p) + dst = append(dst, params[i]) } return dst } @@ -586,8 +586,8 @@ func flattenStruct(dst []Param, s *types.Struct) []Param { } func (w *Writer) constructParams(params []Param, names []string) (res []string) { - for _, p := range params { - n, s := unwrapStruct(p.Type) + for i := range params { + n, s := unwrapStruct(params[i].Type) if s != nil { var v string v, names = w.constructStruct(n, s, names) @@ -633,9 +633,9 @@ func (w *Writer) hookShortcut(trace *Trace, hook Hook) { params = flattenParams(hook.Func.Params) names = w.declareParams(params) ) - for i, p := range params { + for i := range params { w.code(`, `) - w.code(names[i], ` `, w.typeString(p.Type)) + w.code(names[i], ` `, w.typeString(params[i].Type)) } w.code(`)`) if hook.Func.HasResult() { @@ -682,11 +682,11 @@ func (w *Writer) hookFuncShortcut(fn *Func, name string) { params = flattenParams(fn.Params) names = w.declareParams(params) ) - for i, p := range params { + for i := range params { if i > 0 { w.code(`, `) } - w.code(names[i], ` `, w.typeString(p.Type)) + w.code(names[i], ` `, w.typeString(params[i].Type)) } w.code(`)`) if fn.HasResult() { @@ -746,24 +746,24 @@ func (w *Writer) zeroReturn(fn *Func) { func (w *Writer) funcParams(params []Param) (vars []string) { w.code(`(`) - for i, p := range params { + for i := range params { if i > 0 { w.code(`, `) } - vars = append(vars, w.funcParam(p)) + vars = append(vars, w.funcParam(¶ms[i])) } w.code(`)`) return } -func (w *Writer) funcParam(p Param) (name string) { +func (w *Writer) funcParam(p *Param) (name string) { name = w.declare(nameParam(p)) w.code(name, ` `) w.code(w.typeString(p.Type)) return name } -func (w *Writer) funcParamSign(p Param) { +func (w *Writer) funcParamSign(p *Param) { name := nameParam(p) if len(name) == 1 || isPredeclared(name) { name = "_" @@ -803,14 +803,14 @@ func (w *Writer) funcResults(fn *Func) { func (w *Writer) funcSignatureFlags(fn *Func, flags flags) { haveNames := haveNames(fn.Params) w.code(`func(`) - for i, p := range fn.Params { + for i := range fn.Params { if i > 0 { w.code(`, `) } if flags.has(docs) && haveNames { - w.funcParamSign(p) + w.funcParamSign(&fn.Params[i]) } else { - w.code(w.typeString(p.Type)) + w.code(w.typeString(fn.Params[i].Type)) } } w.code(`)`) @@ -832,14 +832,14 @@ func (w *Writer) shortcutFuncSignFlags(fn *Func, flags flags) { haveNames = haveNames(params) ) w.code(`func(`) - for i, p := range params { + for i := range params { if i > 0 { w.code(`, `) } if flags.has(docs) && haveNames { - w.funcParamSign(p) + w.funcParamSign(¶ms[i]) } else { - w.code(w.typeString(p.Type)) + w.code(w.typeString(params[i].Type)) } } w.code(`)`) @@ -869,8 +869,8 @@ func (w *Writer) shortcutFuncResults(fn *Func) { } func haveNames(params []Param) bool { - for _, p := range params { - name := nameParam(p) + for i := range params { + name := nameParam(¶ms[i]) if len(name) > 1 && !isPredeclared(name) { return true } diff --git a/internal/conn/conn.go b/internal/conn/conn.go index 5fddb04c1..97833b7bb 100644 --- a/internal/conn/conn.go +++ b/internal/conn/conn.go @@ -46,10 +46,6 @@ type Conn interface { Unban() State } -func (c *conn) Address() string { - return c.endpoint.Address() -} - type conn struct { mtx sync.RWMutex config Config // ro access @@ -63,6 +59,10 @@ type conn struct { onTransportErrors []func(ctx context.Context, cc Conn, cause error) } +func (c *conn) Address() string { + return c.endpoint.Address() +} + func (c *conn) Ping(ctx context.Context) error { cc, err := c.realConn(ctx) if err != nil { diff --git a/internal/credentials/access_token.go b/internal/credentials/access_token.go index 9370c631e..f3b461b9f 100644 --- a/internal/credentials/access_token.go +++ b/internal/credentials/access_token.go @@ -11,7 +11,7 @@ type accessTokenCredentials struct { sourceInfo string } -func NewAccessTokenCredentials(token string, sourceInfo string) Credentials { +func NewAccessTokenCredentials(token, sourceInfo string) Credentials { return &accessTokenCredentials{ token: token, sourceInfo: sourceInfo, diff --git a/internal/credentials/static.go b/internal/credentials/static.go index 2c404dd3a..ef646fdbf 100644 --- a/internal/credentials/static.go +++ b/internal/credentials/static.go @@ -16,7 +16,7 @@ import ( "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors" ) -func NewStaticCredentials(user, password string, authEndpoint string, opts ...grpc.DialOption) Credentials { +func NewStaticCredentials(user, password, authEndpoint string, opts ...grpc.DialOption) Credentials { return &staticCredentials{ user: user, password: password, diff --git a/internal/discovery/config/config.go b/internal/discovery/config/config.go index 315bd5501..ebcdce783 100644 --- a/internal/discovery/config/config.go +++ b/internal/discovery/config/config.go @@ -18,46 +18,46 @@ type Config struct { endpoint string database string secure bool - meta meta.Meta + meta *meta.Meta interval time.Duration trace *trace.Discovery } -func New(opts ...Option) Config { - c := Config{ +func New(opts ...Option) *Config { + c := &Config{ interval: DefaultInterval, trace: &trace.Discovery{}, } for _, o := range opts { if o != nil { - o(&c) + o(c) } } return c } -func (c Config) Meta() meta.Meta { +func (c *Config) Meta() *meta.Meta { return c.meta } -func (c Config) Interval() time.Duration { +func (c *Config) Interval() time.Duration { return c.interval } -func (c Config) Endpoint() string { +func (c *Config) Endpoint() string { return c.endpoint } -func (c Config) Database() string { +func (c *Config) Database() string { return c.database } -func (c Config) Secure() bool { +func (c *Config) Secure() bool { return c.secure } -func (c Config) Trace() *trace.Discovery { +func (c *Config) Trace() *trace.Discovery { return c.trace } @@ -94,7 +94,7 @@ func WithSecure(ssl bool) Option { // WithMeta is not for user. // // This option add meta information about database connection -func WithMeta(meta meta.Meta) Option { +func WithMeta(meta *meta.Meta) Option { return func(c *Config) { c.meta = meta } diff --git a/internal/discovery/discovery.go b/internal/discovery/discovery.go index 63c8e4eba..b79c62ba5 100644 --- a/internal/discovery/discovery.go +++ b/internal/discovery/discovery.go @@ -18,7 +18,7 @@ import ( "github.com/ydb-platform/ydb-go-sdk/v3/trace" ) -func New(cc grpc.ClientConnInterface, config config.Config) *Client { +func New(cc grpc.ClientConnInterface, config *config.Config) *Client { return &Client{ config: config, cc: cc, @@ -29,7 +29,7 @@ func New(cc grpc.ClientConnInterface, config config.Config) *Client { var _ discovery.Client = &Client{} type Client struct { - config config.Config + config *config.Config cc grpc.ClientConnInterface client Ydb_Discovery_V1.DiscoveryServiceClient } diff --git a/internal/endpoint/endpoint.go b/internal/endpoint/endpoint.go index c60dca6d5..139829cac 100644 --- a/internal/endpoint/endpoint.go +++ b/internal/endpoint/endpoint.go @@ -53,7 +53,7 @@ func (e *endpoint) Copy() Endpoint { func (e *endpoint) String() string { e.mu.RLock() defer e.mu.RUnlock() - return fmt.Sprintf(`{id:%d,address:"%s",local:%t,location:"%s",loadFactor:%f,lastUpdated:"%s"}`, + return fmt.Sprintf(`{id:%d,address:%q,local:%t,location:%q,loadFactor:%f,lastUpdated:%q}`, e.id, e.address, e.local, diff --git a/internal/grpcwrapper/rawtopic/client.go b/internal/grpcwrapper/rawtopic/client.go index 488fa930d..d5081bf80 100644 --- a/internal/grpcwrapper/rawtopic/client.go +++ b/internal/grpcwrapper/rawtopic/client.go @@ -19,7 +19,7 @@ func NewClient(service Ydb_Topic_V1.TopicServiceClient) Client { return Client{service: service} } -func (c *Client) AlterTopic(ctx context.Context, req AlterTopicRequest) (res AlterTopicResult, err error) { +func (c *Client) AlterTopic(ctx context.Context, req *AlterTopicRequest) (res AlterTopicResult, err error) { resp, err := c.service.AlterTopic(ctx, req.ToProto()) if err != nil { return res, xerrors.WithStackTrace(fmt.Errorf("ydb: alter topic grpc failed: %w", err)) @@ -30,7 +30,7 @@ func (c *Client) AlterTopic(ctx context.Context, req AlterTopicRequest) (res Alt func (c *Client) CreateTopic( ctx context.Context, - req CreateTopicRequest, + req *CreateTopicRequest, ) (res CreateTopicResult, err error) { resp, err := c.service.CreateTopic(ctx, req.ToProto()) if err != nil { diff --git a/internal/meta/meta.go b/internal/meta/meta.go index da9477f19..8f2c3ebe4 100644 --- a/internal/meta/meta.go +++ b/internal/meta/meta.go @@ -16,15 +16,15 @@ func New( credentials credentials.Credentials, trace *trace.Driver, opts ...Option, -) Meta { - m := Meta{ +) *Meta { + m := &Meta{ trace: trace, credentials: credentials, database: database, } for _, o := range opts { if o != nil { - o(&m) + o(m) } } return m @@ -72,7 +72,7 @@ type Meta struct { capabilities []string } -func (m Meta) meta(ctx context.Context) (_ metadata.MD, err error) { +func (m *Meta) meta(ctx context.Context) (_ metadata.MD, err error) { md, has := metadata.FromOutgoingContext(ctx) if !has { md = metadata.MD{} @@ -124,7 +124,7 @@ func (m Meta) meta(ctx context.Context) (_ metadata.MD, err error) { return md, nil } -func (m Meta) Context(ctx context.Context) (_ context.Context, err error) { +func (m *Meta) Context(ctx context.Context) (_ context.Context, err error) { md, err := m.meta(ctx) if err != nil { return ctx, xerrors.WithStackTrace(err) diff --git a/internal/scheme/helpers/check_exists.go b/internal/scheme/helpers/check_exists.go index 1448900a0..5adfd7314 100644 --- a/internal/scheme/helpers/check_exists.go +++ b/internal/scheme/helpers/check_exists.go @@ -40,14 +40,14 @@ func IsDirectoryExists(ctx context.Context, c schemeClient, directory string) ( if err != nil { return false, xerrors.WithStackTrace(err) } - for _, e := range d.Children { - if e.Name != childDirectory { + for i := range d.Children { + if d.Children[i].Name != childDirectory { continue } - if e.Type != scheme.EntryDirectory { + if t := d.Children[i].Type; t != scheme.EntryDirectory { return false, xerrors.WithStackTrace(fmt.Errorf( "entry '%s' in path '%s' is not a directory: %s", - childDirectory, parentDirectory, e.Type.String(), + childDirectory, parentDirectory, t.String(), )) } return true, nil @@ -79,14 +79,14 @@ func IsTableExists(ctx context.Context, c schemeClient, absTablePath string) ( if err != nil { return false, err } - for _, e := range d.Children { - if e.Name != tableName { + for i := range d.Children { + if d.Children[i].Name != tableName { continue } - if e.Type != scheme.EntryTable { + if d.Children[i].Type != scheme.EntryTable { return false, xerrors.WithStackTrace(fmt.Errorf( "entry '%s' in path '%s' is not a table: %s", - tableName, directory, e.Type.String(), + tableName, directory, d.Children[i].Type.String(), )) } return true, nil diff --git a/internal/table/client.go b/internal/table/client.go index 1a7c0afe6..044f7291a 100644 --- a/internal/table/client.go +++ b/internal/table/client.go @@ -33,7 +33,7 @@ type balancer interface { nodeChecker } -func New(balancer balancer, config config.Config) *Client { +func New(balancer balancer, config *config.Config) *Client { return newClient(balancer, func(ctx context.Context) (s *session, err error) { return newSession(ctx, balancer, config) }, config) @@ -42,7 +42,7 @@ func New(balancer balancer, config config.Config) *Client { func newClient( balancer balancer, builder sessionBuilder, - config config.Config, + config *config.Config, ) *Client { var ( ctx = context.Background() @@ -78,7 +78,7 @@ func newClient( // A Client is safe for use by multiple goroutines simultaneously. type Client struct { // read-only fields - config config.Config + config *config.Config build sessionBuilder cc grpc.ClientConnInterface nodeChecker nodeChecker @@ -352,9 +352,9 @@ type getOptions struct { type getOption func(o *getOptions) -func withTrace(t trace.Table) getOption { +func withTrace(t *trace.Table) getOption { return func(o *getOptions) { - o.t = o.t.Compose(&t) + o.t = o.t.Compose(t) } } @@ -703,7 +703,7 @@ func (c *Client) internalPoolGC(ctx context.Context, idleThreshold time.Duration // Note that returning a pointer reduces allocations on sync.Pool usage – // sync.Client.Get() returns empty interface, which leads to allocation for // non-pointer values. -func (c *Client) internalPoolGetWaitCh() *chan *session { +func (c *Client) internalPoolGetWaitCh() *chan *session { //nolint:gocritic if c.testHookGetWaitCh != nil { c.testHookGetWaitCh() } @@ -719,7 +719,7 @@ func (c *Client) internalPoolGetWaitCh() *chan *session { // use. // Note that ch MUST NOT be owned by any goroutine at the call moment and ch // MUST NOT contain any value. -func (c *Client) internalPoolPutWaitCh(ch *chan *session) { +func (c *Client) internalPoolPutWaitCh(ch *chan *session) { //nolint:gocritic c.waitChPool.Put(ch) } diff --git a/internal/table/client_test.go b/internal/table/client_test.go index 3f96f5945..c4ad6a2a3 100644 --- a/internal/table/client_test.go +++ b/internal/table/client_test.go @@ -136,7 +136,7 @@ func TestSessionPoolCloseWhenWaiting(t *testing.T) { go func() { _, err := p.internalPoolGet( context.Background(), - withTrace(trace.Table{ + withTrace(&trace.Table{ OnPoolGet: func(trace.TablePoolGetStartInfo) func(trace.TablePoolGetDoneInfo) { get <- struct{}{} return nil @@ -549,7 +549,7 @@ func TestSessionPoolSizeLimitOverflow(t *testing.T) { go func() { session, err := p.internalPoolGet( context.Background(), - withTrace(trace.Table{ + withTrace(&trace.Table{ OnPoolGet: func(trace.TablePoolGetStartInfo) func(trace.TablePoolGetDoneInfo) { get <- struct{}{} return nil diff --git a/internal/table/config/config.go b/internal/table/config/config.go index 09b28774c..c6723b167 100644 --- a/internal/table/config/config.go +++ b/internal/table/config/config.go @@ -25,11 +25,11 @@ const ( DefaultSessionPoolKeepAliveTimeout = 500 * time.Millisecond ) -func New(opts ...Option) Config { +func New(opts ...Option) *Config { c := defaults() for _, o := range opts { if o != nil { - o(&c) + o(c) } } return c @@ -161,19 +161,19 @@ type Config struct { } // Trace defines trace over table client calls -func (c Config) Trace() *trace.Table { +func (c *Config) Trace() *trace.Table { return c.trace } // Clock defines clock -func (c Config) Clock() clockwork.Clock { +func (c *Config) Clock() clockwork.Clock { return c.clock } // SizeLimit is an upper bound of pooled sessions. // If SizeLimit is less than or equal to zero then the // DefaultSessionPoolSizeLimit variable is used as a limit. -func (c Config) SizeLimit() int { +func (c *Config) SizeLimit() int { return c.sizeLimit } @@ -183,12 +183,12 @@ func (c Config) SizeLimit() int { // If KeepAliveMinSize is zero, the DefaultKeepAliveMinSize is used // // Deprecated: table client do not supports background session keep-aliving now -func (c Config) KeepAliveMinSize() int { +func (c *Config) KeepAliveMinSize() int { return DefaultKeepAliveMinSize } // IgnoreTruncated specifies behavior on truncated flag -func (c Config) IgnoreTruncated() bool { +func (c *Config) IgnoreTruncated() bool { return c.ignoreTruncated } @@ -200,7 +200,7 @@ func (c Config) IgnoreTruncated() bool { // If IdleKeepAliveThreshold is equal to zero, it will be set to DefaultIdleKeepAliveThreshold // // Deprecated: table client do not supports background session keep-aliving now -func (c Config) IdleKeepAliveThreshold() int { +func (c *Config) IdleKeepAliveThreshold() int { return DefaultIdleKeepAliveThreshold } @@ -209,7 +209,7 @@ func (c Config) IdleKeepAliveThreshold() int { // // If IdleThreshold is less than zero then there is no idle limit. // If IdleThreshold is zero, then the DefaultSessionPoolIdleThreshold value is used. -func (c Config) IdleThreshold() time.Duration { +func (c *Config) IdleThreshold() time.Duration { return c.idleThreshold } @@ -217,24 +217,24 @@ func (c Config) IdleThreshold() time.Duration { // If KeepAliveTimeout is less than or equal to zero then the DefaultSessionPoolKeepAliveTimeout is used. // // Deprecated: table client do not supports background session keep-aliving now -func (c Config) KeepAliveTimeout() time.Duration { +func (c *Config) KeepAliveTimeout() time.Duration { return DefaultSessionPoolKeepAliveTimeout } // CreateSessionTimeout limits maximum time spent on Create session request -func (c Config) CreateSessionTimeout() time.Duration { +func (c *Config) CreateSessionTimeout() time.Duration { return c.createSessionTimeout } // DeleteTimeout limits maximum time spent on Delete request // // If DeleteTimeout is less than or equal to zero then the DefaultSessionPoolDeleteTimeout is used. -func (c Config) DeleteTimeout() time.Duration { +func (c *Config) DeleteTimeout() time.Duration { return c.deleteTimeout } -func defaults() Config { - return Config{ +func defaults() *Config { + return &Config{ sizeLimit: DefaultSessionPoolSizeLimit, createSessionTimeout: DefaultSessionPoolCreateSessionTimeout, deleteTimeout: DefaultSessionPoolDeleteTimeout, diff --git a/internal/table/data_query.go b/internal/table/data_query.go index 6b1098d3c..c5063a30e 100644 --- a/internal/table/data_query.go +++ b/internal/table/data_query.go @@ -61,7 +61,7 @@ func queryFromText(s string) query { return textDataQuery(s) } -func queryPrepared(id string, query string) query { +func queryPrepared(id, query string) query { return preparedDataQuery{ id: id, query: query, diff --git a/internal/table/retry.go b/internal/table/retry.go index 0392a15f0..1097027c7 100644 --- a/internal/table/retry.go +++ b/internal/table/retry.go @@ -40,9 +40,9 @@ func isRetryCalledAbove(ctx context.Context) bool { func doTx( ctx context.Context, c SessionProvider, - config config.Config, + config *config.Config, op table.TxOperation, - opts table.Options, + opts *table.Options, ) (err error) { if opts.Trace == nil { opts.Trace = &trace.Table{} @@ -112,9 +112,9 @@ func doTx( func do( ctx context.Context, c SessionProvider, - config config.Config, + config *config.Config, op table.Operation, - opts table.Options, + opts *table.Options, ) (err error) { if opts.Trace == nil { opts.Trace = &trace.Table{} @@ -190,8 +190,8 @@ func retryBackoff( return nil } -func retryOptions(trace *trace.Table, opts ...table.Option) table.Options { - options := table.Options{ +func retryOptions(trace *trace.Table, opts ...table.Option) *table.Options { + options := &table.Options{ Trace: trace, FastBackoff: backoff.Fast, SlowBackoff: backoff.Slow, @@ -201,7 +201,7 @@ func retryOptions(trace *trace.Table, opts ...table.Option) table.Options { } for _, o := range opts { if o != nil { - o(&options) + o(options) } } return options diff --git a/internal/table/retry_test.go b/internal/table/retry_test.go index 3c05394a1..1497f0f52 100644 --- a/internal/table/retry_test.go +++ b/internal/table/retry_test.go @@ -48,7 +48,7 @@ func TestRetryerBackoffRetryCancelation(t *testing.T) { func(ctx context.Context, _ table.Session) error { return testErr }, - table.Options{ + &table.Options{ FastBackoff: testutil.BackoffFunc(func(n int) <-chan time.Time { ch := make(chan time.Time) backoff <- ch @@ -109,7 +109,7 @@ func TestRetryerBadSession(t *testing.T) { xerrors.WithStatusCode(Ydb.StatusIds_BAD_SESSION), ) }, - table.Options{}, + &table.Options{}, ) if !xerrors.Is(err, context.Canceled) { t.Errorf("unexpected error: %v", err) @@ -155,7 +155,7 @@ func TestRetryerSessionClosing(t *testing.T) { s.(*session).SetStatus(table.SessionClosing) return nil }, - table.Options{}, + &table.Options{}, ) if err != nil { t.Errorf("unexpected error: %v", err) @@ -206,7 +206,7 @@ func TestRetryerImmediateReturn(t *testing.T) { func(ctx context.Context, _ table.Session) error { return testErr }, - table.Options{ + &table.Options{ FastBackoff: testutil.BackoffFunc(func(n int) <-chan time.Time { panic("this code will not be called") }), @@ -341,7 +341,7 @@ func TestRetryContextDeadline(t *testing.T) { return errs[r.Int(len(errs))] } }, - table.Options{}, + &table.Options{}, ) }) } @@ -442,7 +442,7 @@ func TestRetryWithCustomErrors(t *testing.T) { } return nil }, - table.Options{}, + &table.Options{}, ) //nolint:nestif if test.retriable { diff --git a/internal/table/scanner/scanner.go b/internal/table/scanner/scanner.go index 2eaebe59b..5c9b85bef 100644 --- a/internal/table/scanner/scanner.go +++ b/internal/table/scanner/scanner.go @@ -179,17 +179,17 @@ func (s *scanner) ScanNamed(namedValues ...named.Value) error { if s.nextItem != 0 { panic("scan row failed: double scan per row") } - for _, v := range namedValues { - if err := s.seekItemByName(v.Name); err != nil { + for i := range namedValues { + if err := s.seekItemByName(namedValues[i].Name); err != nil { return err } - switch t := v.Type; t { + switch t := namedValues[i].Type; t { case named.TypeRequired: - s.scanRequired(v.Value) + s.scanRequired(namedValues[i].Value) case named.TypeOptional: - s.scanOptional(v.Value, false) + s.scanOptional(namedValues[i].Value, false) case named.TypeOptionalWithUseDefault: - s.scanOptional(v.Value, true) + s.scanOptional(namedValues[i].Value, true) default: panic(fmt.Sprintf("unknown type of named.Value: %d", t)) } @@ -294,12 +294,13 @@ func (s *scanner) seekItemByName(name string) error { return s.notFoundColumnName(name) } for i, c := range s.set.Columns { - if name == c.Name { - s.stack.scanItem.name = c.Name - s.stack.scanItem.t = c.Type - s.stack.scanItem.v = s.row.Items[i] - return s.Err() + if name != c.Name { + continue } + s.stack.scanItem.name = c.Name + s.stack.scanItem.t = c.Type + s.stack.scanItem.v = s.row.Items[i] + return s.Err() } return s.notFoundColumnName(name) } @@ -702,7 +703,7 @@ func (s *scanner) setByte(dst *[]byte) { } } -func (s *scanner) trySetByteArray(v interface{}, optional bool, def bool) bool { +func (s *scanner) trySetByteArray(v interface{}, optional, def bool) bool { rv := reflect.ValueOf(v) if rv.Kind() == reflect.Ptr { rv = rv.Elem() diff --git a/internal/table/session.go b/internal/table/session.go index 7f240d731..ca955a2db 100644 --- a/internal/table/session.go +++ b/internal/table/session.go @@ -44,7 +44,7 @@ import ( type session struct { id string tableService Ydb_Table_V1.TableServiceClient - config config.Config + config *config.Config status table.SessionStatus statusMtx sync.RWMutex @@ -109,7 +109,7 @@ func (s *session) isClosing() bool { return s.Status() == table.SessionClosing } -func newSession(ctx context.Context, cc grpc.ClientConnInterface, config config.Config) ( +func newSession(ctx context.Context, cc grpc.ClientConnInterface, config *config.Config) ( s *session, err error, ) { onDone := trace.TableOnSessionNew(config.Trace(), &ctx) diff --git a/internal/topic/topicclientinternal/client.go b/internal/topic/topicclientinternal/client.go index ac036056e..2ba51e6bf 100644 --- a/internal/topic/topicclientinternal/client.go +++ b/internal/topic/topicclientinternal/client.go @@ -70,12 +70,12 @@ func (c *Client) Close(_ context.Context) error { // // Notice: This API is EXPERIMENTAL and may be changed or removed in a later release. func (c *Client) Alter(ctx context.Context, path string, opts ...topicoptions.AlterOption) error { - req := rawtopic.AlterTopicRequest{} + req := &rawtopic.AlterTopicRequest{} req.OperationParams = c.defaultOperationParams req.Path = path for _, o := range opts { if o != nil { - o.ApplyAlterOption(&req) + o.ApplyAlterOption(req) } } @@ -100,13 +100,13 @@ func (c *Client) Create( path string, opts ...topicoptions.CreateOption, ) error { - req := rawtopic.CreateTopicRequest{} + req := &rawtopic.CreateTopicRequest{} req.OperationParams = c.defaultOperationParams req.Path = path for _, o := range opts { if o != nil { - o.ApplyCreateOption(&req) + o.ApplyCreateOption(req) } } diff --git a/internal/topic/topicreaderinternal/batch.go b/internal/topic/topicreaderinternal/batch.go index 7d42a1a2a..277d17441 100644 --- a/internal/topic/topicreaderinternal/batch.go +++ b/internal/topic/topicreaderinternal/batch.go @@ -62,7 +62,11 @@ func newBatch(session *partitionSession, messages []*PublicMessage) (*PublicBatc }, nil } -func newBatchFromStream(decoders decoderMap, session *partitionSession, sb rawtopicreader.Batch) (*PublicBatch, error) { +func newBatchFromStream( + decoders decoderMap, + session *partitionSession, + sb rawtopicreader.Batch, //nolint:gocritic +) (*PublicBatch, error) { messages := make([]*PublicMessage, len(sb.MessageData)) prevOffset := session.lastReceivedMessageOffset() for i := range sb.MessageData { diff --git a/internal/topic/topicreaderinternal/partition_session.go b/internal/topic/topicreaderinternal/partition_session.go index 93721a130..20c6ecd21 100644 --- a/internal/topic/topicreaderinternal/partition_session.go +++ b/internal/topic/topicreaderinternal/partition_session.go @@ -91,7 +91,7 @@ func (s *partitionSession) setLastReceivedMessageOffset(v rawtopicreader.Offset) type partitionSessionStorage struct { m sync.RWMutex - sessions map[partitionSessionID]sessionInfo + sessions map[partitionSessionID]*sessionInfo removeIndex int lastCompactedTime time.Time @@ -99,7 +99,7 @@ type partitionSessionStorage struct { } func (c *partitionSessionStorage) init() { - c.sessions = make(map[partitionSessionID]sessionInfo) + c.sessions = make(map[partitionSessionID]*sessionInfo) c.lastCompactedTime = time.Now() } @@ -110,7 +110,7 @@ func (c *partitionSessionStorage) Add(session *partitionSession) error { if _, ok := c.sessions[session.partitionSessionID]; ok { return xerrors.WithStackTrace(fmt.Errorf("session id already existed: %v", session.partitionSessionID)) } - c.sessions[session.partitionSessionID] = sessionInfo{Session: session} + c.sessions[session.partitionSessionID] = &sessionInfo{Session: session} return nil } @@ -118,8 +118,8 @@ func (c *partitionSessionStorage) Get(id partitionSessionID) (*partitionSession, c.m.RLock() defer c.m.RUnlock() - partitionInfo := c.sessions[id] - if partitionInfo.Session == nil { + partitionInfo, has := c.sessions[id] + if !has || partitionInfo.Session == nil { return nil, xerrors.WithStackTrace(fmt.Errorf("ydb: read undefined partition session with id: %v", id)) } @@ -155,8 +155,7 @@ func (c *partitionSessionStorage) isNeedCompactionNeedLock(now time.Time) bool { } func (c *partitionSessionStorage) doCompactionNeedLock(now time.Time) { - newSessions := make(map[partitionSessionID]sessionInfo, len(c.sessions)) - + newSessions := make(map[partitionSessionID]*sessionInfo, len(c.sessions)) for sessionID, info := range c.sessions { if info.IsGarbage(c.removeIndex, now) { continue diff --git a/internal/topic/topicreaderinternal/reader.go b/internal/topic/topicreaderinternal/reader.go index 44cf4ca76..3af7255a7 100644 --- a/internal/topic/topicreaderinternal/reader.go +++ b/internal/topic/topicreaderinternal/reader.go @@ -70,6 +70,8 @@ type PublicReadBatchOption interface { Apply(options ReadMessageBatchOptions) ReadMessageBatchOptions } +type readExplicitMessagesCount int + // Apply // // # Experimental @@ -105,11 +107,11 @@ func NewReader( readerConnector, cfg.OperationTimeout(), cfg.RetrySettings, - cfg.Tracer, + cfg.Trace, cfg.BaseContext, ), defaultBatchConfig: cfg.DefaultBatchConfig, - tracer: cfg.Tracer, + tracer: cfg.Trace, readerID: readerID, } @@ -120,8 +122,6 @@ func (r *Reader) Close(ctx context.Context) error { return r.reader.CloseWithError(ctx, xerrors.WithStackTrace(errReaderClosed)) } -type readExplicitMessagesCount int - // ReadMessage read exactly one message func (r *Reader) ReadMessage(ctx context.Context) (*PublicMessage, error) { res, err := r.ReadMessageBatch(ctx, readExplicitMessagesCount(1)) @@ -143,7 +143,6 @@ func (r *Reader) ReadMessageBatch(ctx context.Context, opts ...PublicReadBatchOp } } -forReadBatch: for { if err = ctx.Err(); err != nil { return nil, err @@ -156,10 +155,9 @@ forReadBatch: // if batch context is canceled - do not return it to client // and read next batch - if batch.Context().Err() != nil { - continue forReadBatch + if batch.Context().Err() == nil { + return batch, nil } - return batch, nil } } @@ -234,7 +232,7 @@ func WithCredentials(cred credentials.Credentials) PublicReaderOption { func WithTrace(tracer *trace.Topic) PublicReaderOption { return func(cfg *ReaderConfig) { - cfg.Tracer = cfg.Tracer.Compose(tracer) + cfg.Trace = cfg.Trace.Compose(tracer) } } @@ -247,7 +245,7 @@ func convertNewParamsToStreamConfig( cfg.Consumer = consumer // make own copy, for prevent changing internal states if readSelectors will change outside - cfg.ReadSelectors = make([]PublicReadSelector, len(readSelectors)) + cfg.ReadSelectors = make([]*PublicReadSelector, len(readSelectors)) for i := range readSelectors { cfg.ReadSelectors[i] = readSelectors[i].Clone() } @@ -278,9 +276,7 @@ type PublicReadSelector struct { // # Experimental // // Notice: This API is EXPERIMENTAL and may be changed or removed in a later release. -func (s PublicReadSelector) Clone() PublicReadSelector { - dst := s - dst.Partitions = clone.Int64Slice(s.Partitions) - - return dst +func (s PublicReadSelector) Clone() *PublicReadSelector { //nolint:gocritic + s.Partitions = clone.Int64Slice(s.Partitions) + return &s } diff --git a/internal/topic/topicreaderinternal/stream_reader_impl.go b/internal/topic/topicreaderinternal/stream_reader_impl.go index 2bf88f2eb..c7058ce3a 100644 --- a/internal/topic/topicreaderinternal/stream_reader_impl.go +++ b/internal/topic/topicreaderinternal/stream_reader_impl.go @@ -64,8 +64,8 @@ type topicStreamReaderConfig struct { Cred credentials.Credentials CredUpdateInterval time.Duration Consumer string - ReadSelectors []PublicReadSelector - Tracer *trace.Topic + ReadSelectors []*PublicReadSelector + Trace *trace.Topic GetPartitionStartOffsetCallback PublicGetPartitionStartOffsetFunc CommitMode PublicCommitMode Decoders decoderMap @@ -80,7 +80,7 @@ func newTopicStreamReaderConfig() topicStreamReaderConfig { CommitMode: CommitModeAsync, CommitterBatchTimeLag: time.Second, Decoders: newDecoderMap(), - Tracer: &trace.Topic{}, + Trace: &trace.Topic{}, } } @@ -110,7 +110,7 @@ func (cfg *topicStreamReaderConfig) initMessage() *rawtopicreader.InitRequest { func newTopicStreamReader( readerID int64, stream RawTopicReaderStream, - cfg topicStreamReaderConfig, + cfg topicStreamReaderConfig, //nolint:gocritic ) (_ *topicStreamReaderImpl, err error) { defer func() { if err != nil { @@ -132,7 +132,7 @@ func newTopicStreamReader( func newTopicStreamReaderStopped( readerID int64, stream RawTopicReaderStream, - cfg topicStreamReaderConfig, + cfg topicStreamReaderConfig, //nolint:gocritic ) *topicStreamReaderImpl { labeledContext := pprof.WithLabels(cfg.BaseContext, pprof.Labels("base-context", "topic-stream-reader")) stopPump, cancel := xcontext.WithCancel(labeledContext) @@ -155,7 +155,7 @@ func newTopicStreamReaderStopped( rawMessagesFromBuffer: make(chan rawtopicreader.ServerMessage, 1), } - res.committer = newCommitter(cfg.Tracer, labeledContext, cfg.CommitMode, res.send) + res.committer = newCommitter(cfg.Trace, labeledContext, cfg.CommitMode, res.send) res.committer.BufferTimeLagTrigger = cfg.CommitterBatchTimeLag res.committer.BufferCountTrigger = cfg.CommitterBatchCounterTrigger res.sessionController.init() @@ -168,7 +168,7 @@ func (r *topicStreamReaderImpl) ReadMessageBatch( opts ReadMessageBatchOptions, ) (batch *PublicBatch, err error) { onDone := trace.TopicOnReaderReadMessages( - r.cfg.Tracer, + r.cfg.Trace, ctx, opts.MinCount, opts.MaxCount, @@ -284,7 +284,7 @@ func (r *topicStreamReaderImpl) onStopPartitionSessionRequestFromBuffer( } onDone := trace.TopicOnReaderPartitionReadStopResponse( - r.cfg.Tracer, + r.cfg.Trace, r.readConnectionID, session.Context(), session.Topic, @@ -344,7 +344,7 @@ func (r *topicStreamReaderImpl) Commit(ctx context.Context, commitRange commitRa session := commitRange.partitionSession onDone := trace.TopicOnReaderCommit( - r.cfg.Tracer, + r.cfg.Trace, ctx, session.Topic, session.PartitionID, @@ -387,7 +387,7 @@ func (r *topicStreamReaderImpl) checkCommitRange(commitRange commitRange) error func (r *topicStreamReaderImpl) send(msg rawtopicreader.ClientMessage) error { err := r.stream.Send(msg) if err != nil { - trace.TopicOnReaderError(r.cfg.Tracer, r.readConnectionID, err) + trace.TopicOnReaderError(r.cfg.Trace, r.readConnectionID, err) _ = r.CloseWithError(r.ctx, err) } return err @@ -422,7 +422,7 @@ func (r *topicStreamReaderImpl) setStarted() error { func (r *topicStreamReaderImpl) initSession() (err error) { initMessage := r.cfg.initMessage() - onDone := trace.TopicOnReaderInit(r.cfg.Tracer, r.readConnectionID, initMessage) + onDone := trace.TopicOnReaderInit(r.cfg.Trace, r.readConnectionID, initMessage) defer func() { onDone(r.readConnectionID, err) }() @@ -469,9 +469,9 @@ func (r *topicStreamReaderImpl) readMessagesLoop(ctx context.Context) { for { serverMessage, err := r.stream.Recv() if err != nil { - trace.TopicOnReaderError(r.cfg.Tracer, r.readConnectionID, err) + trace.TopicOnReaderError(r.cfg.Trace, r.readConnectionID, err) if errors.Is(err, rawtopicreader.ErrUnexpectedMessageType) { - trace.TopicOnReaderUnknownGrpcMessage(r.cfg.Tracer, r.readConnectionID, err) + trace.TopicOnReaderUnknownGrpcMessage(r.cfg.Trace, r.readConnectionID, err) // new messages can be added to protocol, it must be backward compatible to old programs // and skip message is safe continue @@ -514,7 +514,7 @@ func (r *topicStreamReaderImpl) readMessagesLoop(ctx context.Context) { r.onUpdateTokenResponse(m) default: trace.TopicOnReaderUnknownGrpcMessage( - r.cfg.Tracer, + r.cfg.Trace, r.readConnectionID, xerrors.WithStackTrace(xerrors.Wrap(fmt.Errorf( "ydb: unexpected message type in stream reader: %v", @@ -553,7 +553,7 @@ func (r *topicStreamReaderImpl) dataRequestLoop(ctx context.Context) { } resCapacity := r.addRestBufferBytes(sum) - trace.TopicOnReaderSentDataRequest(r.cfg.Tracer, r.readConnectionID, sum, resCapacity) + trace.TopicOnReaderSentDataRequest(r.cfg.Trace, r.readConnectionID, sum, resCapacity) if err := r.sendDataRequest(sum); err != nil { return } @@ -593,7 +593,7 @@ func (r *topicStreamReaderImpl) updateTokenLoop(ctx context.Context) { func (r *topicStreamReaderImpl) onReadResponse(msg *rawtopicreader.ReadResponse) (err error) { resCapacity := r.addRestBufferBytes(-msg.BytesSize) - onDone := trace.TopicOnReaderReceiveDataResponse(r.cfg.Tracer, r.readConnectionID, resCapacity, msg) + onDone := trace.TopicOnReaderReceiveDataResponse(r.cfg.Trace, r.readConnectionID, resCapacity, msg) defer func() { onDone(err) }() @@ -640,7 +640,7 @@ func (r *topicStreamReaderImpl) onReadResponse(msg *rawtopicreader.ReadResponse) } func (r *topicStreamReaderImpl) CloseWithError(ctx context.Context, reason error) (closeErr error) { - onDone := trace.TopicOnReaderClose(r.cfg.Tracer, r.readConnectionID, reason) + onDone := trace.TopicOnReaderClose(r.cfg.Trace, r.readConnectionID, reason) defer onDone(closeErr) isFirstClose := false @@ -689,7 +689,7 @@ func (r *topicStreamReaderImpl) onCommitResponse(msg *rawtopicreader.CommitOffse partition.setCommittedOffset(commit.CommittedOffset) trace.TopicOnReaderCommittedNotify( - r.cfg.Tracer, + r.cfg.Trace, r.readConnectionID, partition.Topic, partition.PartitionID, @@ -705,7 +705,7 @@ func (r *topicStreamReaderImpl) onCommitResponse(msg *rawtopicreader.CommitOffse func (r *topicStreamReaderImpl) updateToken(ctx context.Context) { onUpdateToken := trace.TopicOnReaderUpdateToken( - r.cfg.Tracer, + r.cfg.Trace, r.readConnectionID, ) token, err := r.cfg.Cred.Token(ctx) @@ -743,7 +743,7 @@ func (r *topicStreamReaderImpl) onStartPartitionSessionRequestFromBuffer( } onDone := trace.TopicOnReaderPartitionReadStartResponse( - r.cfg.Tracer, + r.cfg.Trace, r.readConnectionID, session.Context(), session.Topic, diff --git a/internal/topic/topicreaderinternal/stream_reader_impl_test.go b/internal/topic/topicreaderinternal/stream_reader_impl_test.go index 6e66a475c..8f74e5d7d 100644 --- a/internal/topic/topicreaderinternal/stream_reader_impl_test.go +++ b/internal/topic/topicreaderinternal/stream_reader_impl_test.go @@ -223,7 +223,7 @@ func TestStreamReaderImpl_OnPartitionCloseHandle(t *testing.T) { readMessagesCtx, readMessagesCtxCancel := xcontext.WithCancel(context.Background()) committedOffset := int64(222) - e.reader.cfg.Tracer.OnReaderPartitionReadStopResponse = func(info trace.TopicReaderPartitionReadStopResponseStartInfo) func(doneInfo trace.TopicReaderPartitionReadStopResponseDoneInfo) { //nolint:lll + e.reader.cfg.Trace.OnReaderPartitionReadStopResponse = func(info trace.TopicReaderPartitionReadStopResponseStartInfo) func(doneInfo trace.TopicReaderPartitionReadStopResponseDoneInfo) { //nolint:lll expected := trace.TopicReaderPartitionReadStopResponseStartInfo{ ReaderConnectionID: e.reader.readConnectionID, PartitionContext: e.partitionSession.ctx, @@ -267,7 +267,7 @@ func TestStreamReaderImpl_OnPartitionCloseHandle(t *testing.T) { readMessagesCtx, readMessagesCtxCancel := xcontext.WithCancel(context.Background()) committedOffset := int64(222) - e.reader.cfg.Tracer.OnReaderPartitionReadStopResponse = func(info trace.TopicReaderPartitionReadStopResponseStartInfo) func(doneInfo trace.TopicReaderPartitionReadStopResponseDoneInfo) { //nolint:lll + e.reader.cfg.Trace.OnReaderPartitionReadStopResponse = func(info trace.TopicReaderPartitionReadStopResponseStartInfo) func(doneInfo trace.TopicReaderPartitionReadStopResponseDoneInfo) { //nolint:lll expected := trace.TopicReaderPartitionReadStopResponseStartInfo{ ReaderConnectionID: e.reader.readConnectionID, PartitionContext: e.partitionSession.ctx, diff --git a/internal/topic/topicwriterinternal/message.go b/internal/topic/topicwriterinternal/message.go index d7885f1bb..2ef3e569e 100644 --- a/internal/topic/topicwriterinternal/message.go +++ b/internal/topic/topicwriterinternal/message.go @@ -181,11 +181,12 @@ func (m *messageWithDataContent) getEncodedBytes(codec rawtopiccommon.Codec) ([] } } -func newMessageDataWithContent(mess Message, encoders *EncoderMap) ( - res messageWithDataContent, -) { - res.encoders = encoders - res.Message = mess - - return res +func newMessageDataWithContent( + message Message, //nolint:gocritic + encoders *EncoderMap, +) messageWithDataContent { + return messageWithDataContent{ + Message: message, + encoders: encoders, + } } diff --git a/internal/topic/topicwriterinternal/queue.go b/internal/topic/topicwriterinternal/queue.go index 8c9235b07..ab5ff7e56 100644 --- a/internal/topic/topicwriterinternal/queue.go +++ b/internal/topic/topicwriterinternal/queue.go @@ -109,17 +109,19 @@ func (q *messageQueue) checkNewMessagesBeforeAddNeedLock(messages []messageWithD } checkedSeqNo := q.lastSeqNo - for _, m := range messages { - if m.SeqNo <= checkedSeqNo { + for i := range messages { + if messages[i].SeqNo <= checkedSeqNo { return xerrors.WithStackTrace(errAddUnorderedMessages) } - checkedSeqNo = m.SeqNo + checkedSeqNo = messages[i].SeqNo } return nil } -func (q *messageQueue) addMessageNeedLock(mess messageWithDataContent) (messageIndex int) { +func (q *messageQueue) addMessageNeedLock( + mess messageWithDataContent, //nolint:gocritic +) (messageIndex int) { q.lastWrittenIndex++ messageIndex = q.lastWrittenIndex diff --git a/internal/topic/topicwriterinternal/writer_reconnector.go b/internal/topic/topicwriterinternal/writer_reconnector.go index 00853685d..3ff3fcbbc 100644 --- a/internal/topic/topicwriterinternal/writer_reconnector.go +++ b/internal/topic/topicwriterinternal/writer_reconnector.go @@ -130,13 +130,17 @@ type WriterReconnector struct { encodersMap *EncoderMap } -func newWriterReconnector(cfg WriterReconnectorConfig) *WriterReconnector { +func newWriterReconnector( + cfg WriterReconnectorConfig, //nolint:gocritic +) *WriterReconnector { res := newWriterReconnectorStopped(cfg) res.start() return res } -func newWriterReconnectorStopped(cfg WriterReconnectorConfig) *WriterReconnector { +func newWriterReconnectorStopped( + cfg WriterReconnectorConfig, //nolint:gocritic +) *WriterReconnector { writerInstanceID, _ := rand.Int(rand.Reader, big.NewInt(math.MaxInt64)) res := &WriterReconnector{ cfg: cfg, @@ -344,9 +348,7 @@ func (w *WriterReconnector) connectionLoop(ctx context.Context) { //nolint:ineffassign,staticcheck streamCtx, streamCtxCancel := createStreamContext() - defer func() { - streamCtxCancel() - }() + defer streamCtxCancel() var reconnectReason error var prevAttemptTime time.Time @@ -395,7 +397,7 @@ func (w *WriterReconnector) connectionLoop(ctx context.Context) { } } -func (w *WriterReconnector) startWriteStream(ctx context.Context, streamCtx context.Context, attempt int) ( +func (w *WriterReconnector) startWriteStream(ctx, streamCtx context.Context, attempt int) ( writer *SingleStreamWriter, err error, ) { diff --git a/internal/topic/topicwriterinternal/writer_reconnector_test.go b/internal/topic/topicwriterinternal/writer_reconnector_test.go index aa864faa5..44a2203ed 100644 --- a/internal/topic/topicwriterinternal/writer_reconnector_test.go +++ b/internal/topic/topicwriterinternal/writer_reconnector_test.go @@ -658,9 +658,9 @@ func newTestMessageWithDataContent(num int) messageWithDataContent { } func newTestMessages(numbers ...int) []Message { - messages := make([]Message, 0, len(numbers)) - for _, num := range numbers { - messages = append(messages, Message{SeqNo: int64(num)}) + messages := make([]Message, len(numbers)) + for i, num := range numbers { + messages[i].SeqNo = int64(num) } return messages } diff --git a/internal/topic/topicwriterinternal/writer_single_stream.go b/internal/topic/topicwriterinternal/writer_single_stream.go index a31cc5f5a..3d835398d 100644 --- a/internal/topic/topicwriterinternal/writer_single_stream.go +++ b/internal/topic/topicwriterinternal/writer_single_stream.go @@ -29,7 +29,7 @@ type SingleStreamWriterConfig struct { } func newSingleStreamWriterConfig( - common WritersCommonConfig, + common WritersCommonConfig, //nolint:gocritic stream RawTopicWriterStream, queue *messageQueue, encodersMap *EncoderMap, @@ -63,7 +63,7 @@ type SingleStreamWriter struct { func NewSingleStreamWriter( ctxForPProfLabelsOnly context.Context, - cfg SingleStreamWriterConfig, + cfg SingleStreamWriterConfig, //nolint:gocritic ) (*SingleStreamWriter, error) { res := newSingleStreamWriterStopped(ctxForPProfLabelsOnly, cfg) err := res.initStream() @@ -77,7 +77,7 @@ func NewSingleStreamWriter( func newSingleStreamWriterStopped( ctxForPProfLabelsOnly context.Context, - cfg SingleStreamWriterConfig, + cfg SingleStreamWriterConfig, //nolint:gocritic ) *SingleStreamWriter { return &SingleStreamWriter{ cfg: cfg, diff --git a/internal/topic/topicwriterinternal/writer_single_stream_test.go b/internal/topic/topicwriterinternal/writer_single_stream_test.go index 8c01d4d30..59e08bc53 100644 --- a/internal/topic/topicwriterinternal/writer_single_stream_test.go +++ b/internal/topic/topicwriterinternal/writer_single_stream_test.go @@ -35,7 +35,9 @@ func TestWriterImpl_CreateInitMessage(t *testing.T) { t.Run("WithoutGetLastSeq", func(t *testing.T) { ctx := xtest.Context(t) - w := newSingleStreamWriterStopped(ctx, SingleStreamWriterConfig{getAutoSeq: false}) + w := newSingleStreamWriterStopped(ctx, + SingleStreamWriterConfig{getAutoSeq: false}, + ) require.False(t, w.createInitRequest().GetLastSeqNo) }) } diff --git a/internal/value/type.go b/internal/value/type.go index 55dc67498..e9d4bdabf 100644 --- a/internal/value/type.go +++ b/internal/value/type.go @@ -553,13 +553,13 @@ func (v *StructType) Yql() string { buffer := allocator.Buffers.Get() defer allocator.Buffers.Put(buffer) buffer.WriteString("Struct<") - for i, f := range v.fields { + for i := range v.fields { if i > 0 { buffer.WriteByte(',') } - buffer.WriteString("'" + f.Name + "'") + buffer.WriteString("'" + v.fields[i].Name + "'") buffer.WriteByte(':') - buffer.WriteString(f.T.Yql()) + buffer.WriteString(v.fields[i].T.Yql()) } buffer.WriteByte('>') return buffer.String() @@ -591,10 +591,10 @@ func (v *StructType) toYDB(a *allocator.Allocator) *Ydb.Type { typeStruct.StructType = a.Struct() - for _, filed := range v.fields { + for i := range v.fields { structMember := a.StructMember() - structMember.Name = filed.Name - structMember.Type = filed.T.toYDB(a) + structMember.Name = v.fields[i].Name + structMember.Type = v.fields[i].T.toYDB(a) typeStruct.StructType.Members = append( typeStruct.StructType.Members, structMember, @@ -695,13 +695,13 @@ func (v *variantStructType) Yql() string { buffer := allocator.Buffers.Get() defer allocator.Buffers.Put(buffer) buffer.WriteString("Variant<") - for i, f := range v.fields { + for i := range v.fields { if i > 0 { buffer.WriteByte(',') } - buffer.WriteString("'" + f.Name + "'") + buffer.WriteString("'" + v.fields[i].Name + "'") buffer.WriteByte(':') - buffer.WriteString(f.T.Yql()) + buffer.WriteString(v.fields[i].T.Yql()) } buffer.WriteByte('>') return buffer.String() diff --git a/internal/value/value.go b/internal/value/value.go index 0f67a137a..fa073e09b 100644 --- a/internal/value/value.go +++ b/internal/value/value.go @@ -480,7 +480,7 @@ func DecimalValueFromBigInt(v *big.Int, precision, scale uint32) *decimalValue { return DecimalValue(b, precision, scale) } -func DecimalValue(v [16]byte, precision uint32, scale uint32) *decimalValue { +func DecimalValue(v [16]byte, precision, scale uint32) *decimalValue { return &decimalValue{ value: v, innerType: &DecimalType{ @@ -503,8 +503,8 @@ type ( func (v *dictValue) Values() map[Value]Value { values := make(map[Value]Value, len(v.values)) - for _, vv := range v.values { - values[vv.K] = vv.V + for i := range v.values { + values[v.values[i].K] = v.values[i].V } return values } @@ -517,13 +517,13 @@ func (v *dictValue) Yql() string { buffer := allocator.Buffers.Get() defer allocator.Buffers.Put(buffer) buffer.WriteByte('{') - for i, value := range v.values { + for i := range v.values { if i != 0 { buffer.WriteByte(',') } - buffer.WriteString(value.K.Yql()) + buffer.WriteString(v.values[i].K.Yql()) buffer.WriteByte(':') - buffer.WriteString(value.V.Yql()) + buffer.WriteString(v.values[i].V.Yql()) } buffer.WriteByte('}') return buffer.String() @@ -540,11 +540,11 @@ func (v *dictValue) toYDB(a *allocator.Allocator) *Ydb.Value { } vvv := a.Value() - for _, vv := range values { + for i := range values { pair := a.Pair() - pair.Key = vv.K.toYDB(a) - pair.Payload = vv.V.toYDB(a) + pair.Key = values[i].K.toYDB(a) + pair.Payload = values[i].V.toYDB(a) vvv.Pairs = append(vvv.Pairs, pair) } @@ -943,7 +943,7 @@ func (v intervalValue) Yql() string { } if d > 0 { seconds := float64(d) / float64(time.Second) - buffer.WriteString(fmt.Sprintf("%0.6f", seconds)) + fmt.Fprintf(buffer, "%0.6f", seconds) buffer.WriteByte('S') } buffer.WriteByte('"') @@ -1232,8 +1232,8 @@ type ( func (v *structValue) Fields() map[string]Value { fields := make(map[string]Value, len(v.fields)) - for _, f := range v.fields { - fields[f.Name] = f.V + for i := range v.fields { + fields[v.fields[i].Name] = v.fields[i].V } return fields } @@ -1246,12 +1246,12 @@ func (v *structValue) Yql() string { buffer := allocator.Buffers.Get() defer allocator.Buffers.Put(buffer) buffer.WriteString("<|") - for i, field := range v.fields { + for i := range v.fields { if i != 0 { buffer.WriteByte(',') } - buffer.WriteString("`" + field.Name + "`:") - buffer.WriteString(field.V.Yql()) + buffer.WriteString("`" + v.fields[i].Name + "`:") + buffer.WriteString(v.fields[i].V.Yql()) } buffer.WriteString("|>") return buffer.String() @@ -1264,8 +1264,8 @@ func (v *structValue) Type() Type { func (v structValue) toYDB(a *allocator.Allocator) *Ydb.Value { vvv := a.Value() - for _, field := range v.fields { - vvv.Items = append(vvv.Items, field.V.toYDB(a)) + for i := range v.fields { + vvv.Items = append(vvv.Items, v.fields[i].V.toYDB(a)) } return vvv @@ -1276,8 +1276,8 @@ func StructValue(fields ...StructValueField) *structValue { return fields[i].Name < fields[j].Name }) structFields := make([]StructField, 0, len(fields)) - for _, field := range fields { - structFields = append(structFields, StructField{field.Name, field.V.Type()}) + for i := range fields { + structFields = append(structFields, StructField{fields[i].Name, fields[i].V.Type()}) } return &structValue{ t: Struct(structFields...), @@ -1830,9 +1830,9 @@ func (v *variantValue) Yql() string { buffer.WriteByte(',') switch t := v.innerType.(type) { case *variantStructType: - buffer.WriteString(fmt.Sprintf("%q", t.fields[v.idx].Name)) + fmt.Fprintf(buffer, "%q", t.fields[v.idx].Name) case *variantTupleType: - buffer.WriteString("\"" + strconv.FormatUint(uint64(v.idx), 10) + "\"") + fmt.Fprintf(buffer, "\""+strconv.FormatUint(uint64(v.idx), 10)+"\"") } buffer.WriteByte(',') buffer.WriteString(v.Type().Yql()) @@ -2081,10 +2081,10 @@ func ZeroValue(t Type) Value { case *StructType: return StructValue(func() []StructValueField { fields := make([]StructValueField, len(t.fields)) - for i, tt := range t.fields { + for i := range t.fields { fields[i] = StructValueField{ - Name: tt.Name, - V: ZeroValue(tt.T), + Name: t.fields[i].Name, + V: ZeroValue(t.fields[i].T), } } return fields diff --git a/internal/wait/wait.go b/internal/wait/wait.go index dc6eaa6be..5317d34b5 100644 --- a/internal/wait/wait.go +++ b/internal/wait/wait.go @@ -22,7 +22,7 @@ func waitBackoff(ctx context.Context, b backoff.Backoff, i int) error { } } -func Wait(ctx context.Context, fastBackoff backoff.Backoff, slowBackoff backoff.Backoff, t backoff.Type, i int) error { +func Wait(ctx context.Context, fastBackoff, slowBackoff backoff.Backoff, t backoff.Type, i int) error { var b backoff.Backoff switch t { case backoff.TypeNoBackoff: diff --git a/internal/xerrors/operation.go b/internal/xerrors/operation.go index fac647e1b..ce42753c1 100644 --- a/internal/xerrors/operation.go +++ b/internal/xerrors/operation.go @@ -88,7 +88,7 @@ func (e *operationError) Error() string { b := allocator.Buffers.Get() defer allocator.Buffers.Put(b) b.WriteString(e.Name()) - b.WriteString(fmt.Sprintf(" (code = %d", e.code)) + fmt.Fprintf(b, " (code = %d", e.code) if len(e.address) > 0 { b.WriteString(", address = ") b.WriteString(e.address) diff --git a/internal/xresolver/xresolver.go b/internal/xresolver/xresolver.go index 170af9e0d..f2176a729 100644 --- a/internal/xresolver/xresolver.go +++ b/internal/xresolver/xresolver.go @@ -31,8 +31,8 @@ func (c *clientConn) Endpoint() string { func (c *clientConn) UpdateState(state resolver.State) (err error) { onDone := trace.DriverOnResolve(c.trace, c.Endpoint(), func() (addrs []string) { - for _, a := range state.Addresses { - addrs = append(addrs, a.Addr) + for i := range state.Addresses { + addrs = append(addrs, state.Addresses[i].Addr) } return }()) @@ -47,7 +47,7 @@ func (c *clientConn) UpdateState(state resolver.State) (err error) { } func (d *dnsBuilder) Build( - target resolver.Target, + target resolver.Target, //nolint:gocritic cc resolver.ClientConn, opts resolver.BuildOptions, ) (resolver.Resolver, error) { diff --git a/internal/xsql/conn.go b/internal/xsql/conn.go index a24f35ac3..7627f1b21 100644 --- a/internal/xsql/conn.go +++ b/internal/xsql/conn.go @@ -462,8 +462,8 @@ func (c *conn) IsColumnExists(ctx context.Context, tableName, columnName string) if err != nil { return err } - for _, col := range desc.Columns { - if col.Name == columnName { + for i := range desc.Columns { + if desc.Columns[i].Name == columnName { columnExists = true break } @@ -491,8 +491,8 @@ func (c *conn) GetColumns(ctx context.Context, tableName string) (columns []stri if err != nil { return err } - for _, col := range desc.Columns { - columns = append(columns, col.Name) + for i := range desc.Columns { + columns = append(columns, desc.Columns[i].Name) } return nil }, retry.WithIdempotent(true)) @@ -525,9 +525,9 @@ func (c *conn) GetColumnType(ctx context.Context, tableName, columnName string) if err != nil { return err } - for _, col := range desc.Columns { - if col.Name == columnName { - dataType = col.Type.Yql() + for i := range desc.Columns { + if desc.Columns[i].Name == columnName { + dataType = desc.Columns[i].Type.Yql() break } } @@ -626,9 +626,9 @@ func (c *conn) GetTables(ctx context.Context, folder string) (tables []string, e return nil, xerrors.WithStackTrace(err) } - for _, child := range d.Children { - if child.IsTable() { - tables = append(tables, child.Name) + for i := range d.Children { + if d.Children[i].IsTable() { + tables = append(tables, d.Children[i].Name) } } return tables, nil @@ -688,10 +688,10 @@ func (c *conn) GetAllTables(ctx context.Context, folder string) (tables []string return nil, xerrors.WithStackTrace(err) } - for _, child := range d.Children { - if child.IsDirectory() || child.IsTable() { - if canEnter(child.Name) { - queue = append(queue, path.Join(curPath, child.Name)) + for i := range d.Children { + if d.Children[i].IsDirectory() || d.Children[i].IsTable() { + if canEnter(d.Children[i].Name) { + queue = append(queue, path.Join(curPath, d.Children[i].Name)) } } } @@ -714,8 +714,8 @@ func (c *conn) GetIndexes(ctx context.Context, tableName string) (indexes []stri if err != nil { return err } - for _, indexDesc := range desc.Indexes { - indexes = append(indexes, indexDesc.Name) + for i := range desc.Indexes { + indexes = append(indexes, desc.Indexes[i].Name) } return nil }, retry.WithIdempotent(true)) @@ -741,9 +741,9 @@ func (c *conn) GetIndexColumns(ctx context.Context, tableName, indexName string) if err != nil { return err } - for _, indexDesc := range desc.Indexes { - if indexDesc.Name == indexName { - columns = append(columns, indexDesc.IndexColumns...) + for i := range desc.Indexes { + if desc.Indexes[i].Name == indexName { + columns = append(columns, desc.Indexes[i].IndexColumns...) return nil } } diff --git a/internal/xsql/connector.go b/internal/xsql/connector.go index 28463cfcc..29518f4a2 100644 --- a/internal/xsql/connector.go +++ b/internal/xsql/connector.go @@ -113,8 +113,8 @@ func (option traceConnectorOption) Apply(c *Connector) error { return nil } -func WithTrace(t trace.DatabaseSQL, opts ...trace.DatabaseSQLComposeOption) ConnectorOption { - return traceConnectorOption{&t, opts} +func WithTrace(t *trace.DatabaseSQL, opts ...trace.DatabaseSQLComposeOption) ConnectorOption { + return traceConnectorOption{t, opts} } type disableServerBalancerConnectorOption struct{} diff --git a/internal/xsql/dsn_test.go b/internal/xsql/dsn_test.go index c8321e418..309f9bf6a 100644 --- a/internal/xsql/dsn_test.go +++ b/internal/xsql/dsn_test.go @@ -19,7 +19,7 @@ func TestParse(t *testing.T) { } return c } - compareConfigs := func(t *testing.T, lhs, rhs config.Config) { + compareConfigs := func(t *testing.T, lhs, rhs *config.Config) { require.Equal(t, lhs.Secure(), rhs.Secure()) require.Equal(t, lhs.Endpoint(), rhs.Endpoint()) require.Equal(t, lhs.Database(), rhs.Database()) diff --git a/internal/xsql/rows.go b/internal/xsql/rows.go index b7c4377d9..381d340d5 100644 --- a/internal/xsql/rows.go +++ b/internal/xsql/rows.go @@ -118,8 +118,8 @@ type single struct { } func (r *single) Columns() (columns []string) { - for _, v := range r.values { - columns = append(columns, v.Name) + for i := range r.values { + columns = append(columns, r.values[i].Name) } return columns } diff --git a/internal/xsync/mutex.go b/internal/xsync/mutex.go index 1dca15e29..c315bf33f 100644 --- a/internal/xsync/mutex.go +++ b/internal/xsync/mutex.go @@ -4,7 +4,7 @@ import ( "sync" ) -type Mutex struct { +type Mutex struct { //nolint:gocritic sync.Mutex } @@ -15,7 +15,7 @@ func (l *Mutex) WithLock(f func()) { f() } -type RWMutex struct { +type RWMutex struct { //nolint:gocritic sync.RWMutex } diff --git a/internal/xtest/manytimes.go b/internal/xtest/manytimes.go index b1057ead1..cd84603fb 100644 --- a/internal/xtest/manytimes.go +++ b/internal/xtest/manytimes.go @@ -169,11 +169,11 @@ func (tw *testWrapper) flushLogs() { tw.m.Lock() defer tw.m.Unlock() - for _, rec := range tw.logs { - if rec.format == "" { - tw.TB.Log(rec.args...) + for i := range tw.logs { + if tw.logs[i].format == "" { + tw.TB.Log(tw.logs[i].args...) } else { - tw.TB.Logf(rec.format, rec.args...) + tw.TB.Logf(tw.logs[i].format, tw.logs[i].args...) } } diff --git a/log/field.go b/log/field.go index d7e118edc..899c0c4a2 100644 --- a/log/field.go +++ b/log/field.go @@ -142,9 +142,7 @@ func (f Field) checkType(want FieldType) { // It should be used by adapters that don't support f.Type directly. func (f Field) String() string { switch f.ftype { - case IntType: - fallthrough - case Int64Type: + case IntType, Int64Type: return strconv.FormatInt(f.vint, 10) case StringType: return f.vstr @@ -155,7 +153,10 @@ func (f Field) String() string { case StringsType: return fmt.Sprintf("%v", f.StringsValue()) case ErrorType: - return fmt.Sprintf("%v", f.ErrorValue()) + if f.vany == nil || f.vany.(error) == nil { + return "" + } + return f.ErrorValue().Error() case AnyType: if f.vany == nil { return nilPtr @@ -175,28 +176,28 @@ func (f Field) String() string { } // String constructs Field with StringType -func String(key string, value string) Field { +func String(k, v string) Field { return Field{ ftype: StringType, - key: key, - vstr: value, + key: k, + vstr: v, } } // Int constructs Field with IntType -func Int(key string, value int) Field { +func Int(k string, v int) Field { return Field{ ftype: IntType, - key: key, - vint: int64(value), + key: k, + vint: int64(v), } } -func Int64(key string, value int64) Field { +func Int64(k string, v int64) Field { return Field{ ftype: Int64Type, - key: key, - vint: value, + key: k, + vint: v, } } diff --git a/log/join.go b/log/join.go index 74ffc2da5..15543267e 100644 --- a/log/join.go +++ b/log/join.go @@ -1,6 +1,10 @@ package log -import "github.com/ydb-platform/ydb-go-sdk/v3/internal/allocator" +import ( + "unicode/utf8" + + "github.com/ydb-platform/ydb-go-sdk/v3/internal/allocator" +) func joinNamespace(names []string, maxLen int) (join string) { l := 0 @@ -18,7 +22,8 @@ func joinNamespace(names []string, maxLen int) (join string) { } ll := len([]rune(s)) if maxLen != 0 && l > maxLen { - b.WriteRune([]rune(s)[0]) + r, _ := utf8.DecodeRuneInString(s) + b.WriteRune(r) l += 1 - ll } else { b.WriteString(s) diff --git a/log/logger.go b/log/logger.go index 80b57eb21..8679c8365 100644 --- a/log/logger.go +++ b/log/logger.go @@ -136,11 +136,11 @@ func (l *defaultLogger) appendFields(msg string, fields ...Field) string { defer allocator.Buffers.Put(b) b.WriteString(msg) b.WriteString(" {") - for i, field := range fields { + for i := range fields { if i != 0 { b.WriteByte(',') } - fmt.Fprintf(b, `%q:%q`, field.Key(), field.String()) + fmt.Fprintf(b, `%q:%q`, fields[i].Key(), fields[i].String()) } b.WriteByte('}') return b.String() diff --git a/log/topic.go b/log/topic.go index b2d06e3b3..9635c285a 100644 --- a/log/topic.go +++ b/log/topic.go @@ -1,4 +1,3 @@ -//nolint:lll package log import ( @@ -14,7 +13,9 @@ func Topic(l Logger, d trace.Detailer, opts ...Option) (t trace.Topic) { } func internalTopic(l *wrapper, d trace.Detailer) (t trace.Topic) { //nolint:gocyclo - t.OnReaderReconnect = func(info trace.TopicReaderReconnectStartInfo) func(doneInfo trace.TopicReaderReconnectDoneInfo) { + t.OnReaderReconnect = func( + info trace.TopicReaderReconnectStartInfo, + ) func(doneInfo trace.TopicReaderReconnectDoneInfo) { if d.Details()&trace.TopicReaderStreamLifeCycleEvents == 0 { return nil } @@ -37,7 +38,9 @@ func internalTopic(l *wrapper, d trace.Detailer) (t trace.Topic) { //nolint:gocy Bool("was_sent", info.WasSent), ) } - t.OnReaderPartitionReadStartResponse = func(info trace.TopicReaderPartitionReadStartResponseStartInfo) func(stopInfo trace.TopicReaderPartitionReadStartResponseDoneInfo) { + t.OnReaderPartitionReadStartResponse = func( + info trace.TopicReaderPartitionReadStartResponseStartInfo, + ) func(stopInfo trace.TopicReaderPartitionReadStartResponseDoneInfo) { if d.Details()&trace.TopicReaderPartitionEvents == 0 { return nil } @@ -79,7 +82,9 @@ func internalTopic(l *wrapper, d trace.Detailer) (t trace.Topic) { //nolint:gocy } } } - t.OnReaderPartitionReadStopResponse = func(info trace.TopicReaderPartitionReadStopResponseStartInfo) func(trace.TopicReaderPartitionReadStopResponseDoneInfo) { + t.OnReaderPartitionReadStopResponse = func( + info trace.TopicReaderPartitionReadStopResponseStartInfo, + ) func(trace.TopicReaderPartitionReadStopResponseDoneInfo) { if d.Details()&trace.TopicReaderPartitionEvents == 0 { return nil } @@ -148,7 +153,9 @@ func internalTopic(l *wrapper, d trace.Detailer) (t trace.Topic) { //nolint:gocy } } } - t.OnReaderSendCommitMessage = func(info trace.TopicReaderSendCommitMessageStartInfo) func(doneInfo trace.TopicReaderSendCommitMessageDoneInfo) { + t.OnReaderSendCommitMessage = func( + info trace.TopicReaderSendCommitMessageStartInfo, + ) func(trace.TopicReaderSendCommitMessageDoneInfo) { if d.Details()&trace.TopicReaderStreamEvents == 0 { return nil } @@ -258,7 +265,11 @@ func internalTopic(l *wrapper, d trace.Detailer) (t trace.Topic) { //nolint:gocy version(), ) } - t.OnReaderUpdateToken = func(info trace.OnReadUpdateTokenStartInfo) func(updateTokenInfo trace.OnReadUpdateTokenMiddleTokenReceivedInfo) func(doneInfo trace.OnReadStreamUpdateTokenDoneInfo) { + t.OnReaderUpdateToken = func( + info trace.OnReadUpdateTokenStartInfo, + ) func( + updateTokenInfo trace.OnReadUpdateTokenMiddleTokenReceivedInfo, + ) func(doneInfo trace.OnReadStreamUpdateTokenDoneInfo) { if d.Details()&trace.TopicReaderStreamEvents == 0 { return nil } @@ -267,7 +278,9 @@ func internalTopic(l *wrapper, d trace.Detailer) (t trace.Topic) { //nolint:gocy l.Log(ctx, "token updating...", String("reader_connection_id", info.ReaderConnectionID), ) - return func(updateTokenInfo trace.OnReadUpdateTokenMiddleTokenReceivedInfo) func(doneInfo trace.OnReadStreamUpdateTokenDoneInfo) { + return func( + updateTokenInfo trace.OnReadUpdateTokenMiddleTokenReceivedInfo, + ) func(doneInfo trace.OnReadStreamUpdateTokenDoneInfo) { if updateTokenInfo.Error == nil { l.Log(ctx, "got token", String("reader_connection_id", info.ReaderConnectionID), @@ -313,17 +326,19 @@ func internalTopic(l *wrapper, d trace.Detailer) (t trace.Topic) { //nolint:gocy Int("local_capacity", info.LocalBufferSizeAfterSent), ) } - t.OnReaderReceiveDataResponse = func(startInfo trace.TopicReaderReceiveDataResponseStartInfo) func(doneInfo trace.TopicReaderReceiveDataResponseDoneInfo) { + t.OnReaderReceiveDataResponse = func( + info trace.TopicReaderReceiveDataResponseStartInfo, + ) func(trace.TopicReaderReceiveDataResponseDoneInfo) { if d.Details()&trace.TopicReaderMessageEvents == 0 { return nil } ctx := with(context.Background(), TRACE, "ydb", "topic", "reader", "receive", "data", "response") start := time.Now() - partitionsCount, batchesCount, messagesCount := startInfo.DataResponse.GetPartitionBatchMessagesCounts() + partitionsCount, batchesCount, messagesCount := info.DataResponse.GetPartitionBatchMessagesCounts() l.Log(ctx, "data response received, process starting...", - String("reader_connection_id", startInfo.ReaderConnectionID), - Int("received_bytes", startInfo.DataResponse.GetBytesSize()), - Int("local_capacity", startInfo.LocalBufferSizeAfterReceive), + String("reader_connection_id", info.ReaderConnectionID), + Int("received_bytes", info.DataResponse.GetBytesSize()), + Int("local_capacity", info.LocalBufferSizeAfterReceive), Int("partitions_count", partitionsCount), Int("batches_count", batchesCount), Int("messages_count", messagesCount), @@ -331,9 +346,9 @@ func internalTopic(l *wrapper, d trace.Detailer) (t trace.Topic) { //nolint:gocy return func(doneInfo trace.TopicReaderReceiveDataResponseDoneInfo) { if doneInfo.Error == nil { l.Log(ctx, "data response received and processed", - String("reader_connection_id", startInfo.ReaderConnectionID), - Int("received_bytes", startInfo.DataResponse.GetBytesSize()), - Int("local_capacity", startInfo.LocalBufferSizeAfterReceive), + String("reader_connection_id", info.ReaderConnectionID), + Int("received_bytes", info.DataResponse.GetBytesSize()), + Int("local_capacity", info.LocalBufferSizeAfterReceive), Int("partitions_count", partitionsCount), Int("batches_count", batchesCount), Int("messages_count", messagesCount), @@ -342,9 +357,9 @@ func internalTopic(l *wrapper, d trace.Detailer) (t trace.Topic) { //nolint:gocy } else { l.Log(WithLevel(ctx, WARN), "data response received and processed", Error(doneInfo.Error), - String("reader_connection_id", startInfo.ReaderConnectionID), - Int("received_bytes", startInfo.DataResponse.GetBytesSize()), - Int("local_capacity", startInfo.LocalBufferSizeAfterReceive), + String("reader_connection_id", info.ReaderConnectionID), + Int("received_bytes", info.DataResponse.GetBytesSize()), + Int("local_capacity", info.LocalBufferSizeAfterReceive), Int("partitions_count", partitionsCount), Int("batches_count", batchesCount), Int("messages_count", messagesCount), @@ -354,7 +369,9 @@ func internalTopic(l *wrapper, d trace.Detailer) (t trace.Topic) { //nolint:gocy } } } - t.OnReaderReadMessages = func(info trace.TopicReaderReadMessagesStartInfo) func(doneInfo trace.TopicReaderReadMessagesDoneInfo) { + t.OnReaderReadMessages = func( + info trace.TopicReaderReadMessagesStartInfo, + ) func(doneInfo trace.TopicReaderReadMessagesDoneInfo) { if d.Details()&trace.TopicReaderMessageEvents == 0 { return nil } @@ -399,7 +416,9 @@ func internalTopic(l *wrapper, d trace.Detailer) (t trace.Topic) { //nolint:gocy /// /// Topic writer /// - t.OnWriterReconnect = func(info trace.TopicWriterReconnectStartInfo) func(doneInfo trace.TopicWriterReconnectDoneInfo) { + t.OnWriterReconnect = func( + info trace.TopicWriterReconnectStartInfo, + ) func(doneInfo trace.TopicWriterReconnectDoneInfo) { if d.Details()&trace.TopicWriterStreamLifeCycleEvents == 0 { return nil } @@ -432,7 +451,9 @@ func internalTopic(l *wrapper, d trace.Detailer) (t trace.Topic) { //nolint:gocy } } } - t.OnWriterInitStream = func(info trace.TopicWriterInitStreamStartInfo) func(doneInfo trace.TopicWriterInitStreamDoneInfo) { + t.OnWriterInitStream = func( + info trace.TopicWriterInitStreamStartInfo, + ) func(doneInfo trace.TopicWriterInitStreamDoneInfo) { if d.Details()&trace.TopicWriterStreamLifeCycleEvents == 0 { return nil } @@ -494,7 +515,9 @@ func internalTopic(l *wrapper, d trace.Detailer) (t trace.Topic) { //nolint:gocy } } } - t.OnWriterCompressMessages = func(info trace.TopicWriterCompressMessagesStartInfo) func(doneInfo trace.TopicWriterCompressMessagesDoneInfo) { + t.OnWriterCompressMessages = func( + info trace.TopicWriterCompressMessagesStartInfo, + ) func(doneInfo trace.TopicWriterCompressMessagesDoneInfo) { if d.Details()&trace.TopicWriterStreamEvents == 0 { return nil } @@ -534,7 +557,9 @@ func internalTopic(l *wrapper, d trace.Detailer) (t trace.Topic) { //nolint:gocy } } } - t.OnWriterSendMessages = func(info trace.TopicWriterSendMessagesStartInfo) func(doneInfo trace.TopicWriterSendMessagesDoneInfo) { + t.OnWriterSendMessages = func( + info trace.TopicWriterSendMessagesStartInfo, + ) func(doneInfo trace.TopicWriterSendMessagesDoneInfo) { if d.Details()&trace.TopicWriterStreamEvents == 0 { return nil } diff --git a/options.go b/options.go index e5c73e22a..0f6541ff1 100644 --- a/options.go +++ b/options.go @@ -250,7 +250,7 @@ func WithDiscoveryInterval(discoveryInterval time.Duration) Option { } // WithTraceDriver returns deadline which has associated Driver with it. -func WithTraceDriver(trace trace.Driver, opts ...trace.DriverComposeOption) Option { +func WithTraceDriver(trace trace.Driver, opts ...trace.DriverComposeOption) Option { //nolint:gocritic return func(ctx context.Context, c *Driver) error { c.options = append(c.options, config.WithTrace(trace, opts...)) return nil @@ -395,7 +395,7 @@ func WithPanicCallback(panicCallback func(e interface{})) Option { } // WithTraceTable returns table trace option -func WithTraceTable(t trace.Table, opts ...trace.TableComposeOption) Option { +func WithTraceTable(t trace.Table, opts ...trace.TableComposeOption) Option { //nolint:gocritic return func(ctx context.Context, c *Driver) error { c.tableOptions = append( c.tableOptions, @@ -517,7 +517,7 @@ func WithTraceDiscovery(t trace.Discovery, opts ...trace.DiscoveryComposeOption) } // WithTraceTopic adds configured discovery tracer to Driver -func WithTraceTopic(t trace.Topic, opts ...trace.TopicComposeOption) Option { +func WithTraceTopic(t trace.Topic, opts ...trace.TopicComposeOption) Option { //nolint:gocritic return func(ctx context.Context, c *Driver) error { c.topicOptions = append( c.topicOptions, @@ -536,12 +536,12 @@ func WithTraceTopic(t trace.Topic, opts ...trace.TopicComposeOption) Option { } // WithTraceDatabaseSQL adds configured discovery tracer to Driver -func WithTraceDatabaseSQL(t trace.DatabaseSQL, opts ...trace.DatabaseSQLComposeOption) Option { +func WithTraceDatabaseSQL(t trace.DatabaseSQL, opts ...trace.DatabaseSQLComposeOption) Option { //nolint:gocritic return func(ctx context.Context, c *Driver) error { c.databaseSQLOptions = append( c.databaseSQLOptions, xsql.WithTrace( - t, + &t, append( []trace.DatabaseSQLComposeOption{ trace.WithDatabaseSQLPanicCallback(c.panicCallback), diff --git a/retry/retry.go b/retry/retry.go index 1ea95a5c5..3aaced628 100644 --- a/retry/retry.go +++ b/retry/retry.go @@ -191,11 +191,11 @@ func Retry(ctx context.Context, op retryOperation, opts ...retryOption) (err err // Check returns retry mode for queryErr. func Check(err error) (m retryMode) { - code, errType, backoff, deleteSession := xerrors.Check(err) + code, errType, backoffType, deleteSession := xerrors.Check(err) return retryMode{ code: code, errType: errType, - backoff: backoff, + backoff: backoffType, deleteSession: deleteSession, } } diff --git a/sql.go b/sql.go index 5c388cf6b..31638ee49 100644 --- a/sql.go +++ b/sql.go @@ -139,8 +139,11 @@ func WithDefaultScanQueryOptions(opts ...options.ExecuteScanQueryOption) Connect return xsql.WithDefaultScanQueryOptions(opts...) } -func WithDatabaseSQLTrace(t trace.DatabaseSQL, opts ...trace.DatabaseSQLComposeOption) ConnectorOption { - return xsql.WithTrace(t, opts...) +func WithDatabaseSQLTrace( + t trace.DatabaseSQL, //nolint:gocritic + opts ...trace.DatabaseSQLComposeOption, +) ConnectorOption { + return xsql.WithTrace(&t, opts...) } func WithDisableServerBalancer() ConnectorOption { diff --git a/sugar/path.go b/sugar/path.go index c8daf4398..a01b90055 100644 --- a/sugar/path.go +++ b/sugar/path.go @@ -119,12 +119,12 @@ func RemoveRecursive(ctx context.Context, db dbFoRemoveRecursive, pathToRemove s ) } - for _, child := range dir.Children { - pt := path.Join(p, child.Name) + for j := range dir.Children { + pt := path.Join(p, dir.Children[j].Name) if pt == fullSysTablePath { continue } - switch child.Type { + switch t := dir.Children[j].Type; t { case scheme.EntryDirectory: if err = rmPath(i+1, pt); err != nil { return xerrors.WithStackTrace( @@ -152,7 +152,7 @@ func RemoveRecursive(ctx context.Context, db dbFoRemoveRecursive, pathToRemove s default: return xerrors.WithStackTrace( - fmt.Errorf("unknown entry type: %s", child.Type.String()), + fmt.Errorf("unknown entry type: %s", t.String()), ) } } diff --git a/table/options/options.go b/table/options/options.go index a439edc58..5c8c98f76 100644 --- a/table/options/options.go +++ b/table/options/options.go @@ -228,15 +228,15 @@ type columnFamilies []ColumnFamily func (cf columnFamilies) ApplyAlterTableOption(d *AlterTableDesc, a *allocator.Allocator) { d.AddColumnFamilies = make([]*Ydb_Table.ColumnFamily, len(cf)) - for i, c := range cf { - d.AddColumnFamilies[i] = c.toYDB() + for i := range cf { + d.AddColumnFamilies[i] = cf[i].toYDB() } } func (cf columnFamilies) ApplyCreateTableOption(d *CreateTableDesc, a *allocator.Allocator) { d.ColumnFamilies = make([]*Ydb_Table.ColumnFamily, len(cf)) - for i, c := range cf { - d.ColumnFamilies[i] = c.toYDB() + for i := range cf { + d.ColumnFamilies[i] = cf[i].toYDB() } } @@ -936,7 +936,7 @@ func (f executeScanQueryOptionFunc) ApplyExecuteScanQueryOption(d *ExecuteScanQu return f(d) } -var _ ExecuteScanQueryOption = (executeScanQueryOptionFunc)(nil) +var _ ExecuteScanQueryOption = executeScanQueryOptionFunc(nil) // WithExecuteScanQueryMode defines scan query mode: execute or explain func WithExecuteScanQueryMode(m ExecuteScanQueryRequestMode) ExecuteScanQueryOption { diff --git a/table/result/named/named.go b/table/result/named/named.go index d6c374c9a..586a5d077 100644 --- a/table/result/named/named.go +++ b/table/result/named/named.go @@ -15,42 +15,47 @@ type Value struct { Type Type } -// Optional returns Value with key as column name and value as destination +// Optional makes an object with destination address for column value with name columnName +// +// # If column value is NULL, then ScanNamed will write a nil into destination +// // Warning: value must double-pointed data destination -func Optional(key string, value interface{}) Value { - if key == "" { - panic("key must be not empty") +func Optional(columnName string, destination interface{}) Value { + if columnName == "" { + panic("columnName must be not empty") } return Value{ - Name: key, - Value: value, + Name: columnName, + Value: destination, Type: TypeOptional, } } -// Required returns Value with key as column name and value as destination +// Required makes an object with destination address for column value with name columnName +// // Warning: value must single-pointed data destination -func Required(key string, value interface{}) Value { - if key == "" { - panic("key must be not empty") +func Required(columnName string, destinationValueReference interface{}) Value { + if columnName == "" { + panic("columnName must be not empty") } return Value{ - Name: key, - Value: value, + Name: columnName, + Value: destinationValueReference, Type: TypeRequired, } } -// OptionalWithDefault returns Value with key as column name and value as destination +// OptionalWithDefault makes an object with destination address for column value with name columnName +// // If scanned YDB value is NULL - default type value will be applied to value destination // Warning: value must single-pointed data destination -func OptionalWithDefault(key string, value interface{}) Value { - if key == "" { - panic("key must be not empty") +func OptionalWithDefault(columnName string, destinationValueReference interface{}) Value { + if columnName == "" { + panic("columnName must be not empty") } return Value{ - Name: key, - Value: value, + Name: columnName, + Value: destinationValueReference, Type: TypeOptionalWithUseDefault, } } diff --git a/table/table.go b/table/table.go index 8d65cf9ff..bf075898f 100644 --- a/table/table.go +++ b/table/table.go @@ -572,7 +572,7 @@ func WithTxCommitOptions(opts ...options.CommitTransactionOption) Option { } } -func WithTrace(t trace.Table) Option { +func WithTrace(t trace.Table) Option { //nolint:gocritic return func(o *Options) { o.Trace = o.Trace.Compose(&t) } diff --git a/tests/slo/internal/metrics/metrics.go b/tests/slo/internal/metrics/metrics.go index dc1f7abaf..0d9ad434b 100644 --- a/tests/slo/internal/metrics/metrics.go +++ b/tests/slo/internal/metrics/metrics.go @@ -27,7 +27,7 @@ type ( } ) -func New(url string, label string) (*Metrics, error) { +func New(url, label string) (*Metrics, error) { m := &Metrics{ label: label, } @@ -76,7 +76,7 @@ func New(url string, label string) (*Metrics, error) { Collector(m.inflight). Collector(m.latencies) - return m, m.Reset() + return m, m.Reset() //nolint:gocritic } func (m *Metrics) Push() error { diff --git a/testutil/compare.go b/testutil/compare.go index 21fb25011..5e56caf94 100644 --- a/testutil/compare.go +++ b/testutil/compare.go @@ -44,22 +44,22 @@ func unwrapTypedValue(v *Ydb.TypedValue) *Ydb.TypedValue { return &Ydb.TypedValue{Type: typ, Value: val} } -func compare(l *Ydb.TypedValue, r *Ydb.TypedValue) (int, error) { - lTypeID := l.Type.GetTypeId() - rTypeID := r.Type.GetTypeId() +func compare(lhs, rhs *Ydb.TypedValue) (int, error) { + lTypeID := lhs.Type.GetTypeId() + rTypeID := rhs.Type.GetTypeId() switch { case lTypeID != rTypeID: - return 0, notComparableError(l, r) + return 0, notComparableError(lhs, rhs) case lTypeID != Ydb.Type_PRIMITIVE_TYPE_ID_UNSPECIFIED: - return comparePrimitives(lTypeID, l.Value, r.Value) - case l.Type.GetTupleType() != nil && r.Type.GetTupleType() != nil: - return compareTuplesOrLists(expandTuple(l), expandTuple(r)) - case l.Type.GetListType() != nil && r.Type.GetListType() != nil: - return compareTuplesOrLists(expandList(l), expandList(r)) - case l.Type.GetStructType() != nil && r.Type.GetStructType() != nil: - return compareStructs(expandStruct(l), expandStruct(r)) + return comparePrimitives(lTypeID, lhs.Value, rhs.Value) + case lhs.Type.GetTupleType() != nil && rhs.Type.GetTupleType() != nil: + return compareTuplesOrLists(expandTuple(lhs), expandTuple(rhs)) + case lhs.Type.GetListType() != nil && rhs.Type.GetListType() != nil: + return compareTuplesOrLists(expandList(lhs), expandList(rhs)) + case lhs.Type.GetStructType() != nil && rhs.Type.GetStructType() != nil: + return compareStructs(expandStruct(lhs), expandStruct(rhs)) default: - return 0, notComparableError(l, r) + return 0, notComparableError(lhs, rhs) } } @@ -94,13 +94,13 @@ func expandTuple(v *Ydb.TypedValue) []*Ydb.TypedValue { return values } -func notComparableError(l interface{}, r interface{}) error { - return xerrors.WithStackTrace(fmt.Errorf("%w: %v and %v", ErrNotComparable, l, r), xerrors.WithSkipDepth(1)) +func notComparableError(lhs, rhs interface{}) error { + return xerrors.WithStackTrace(fmt.Errorf("%w: %v and %v", ErrNotComparable, lhs, rhs), xerrors.WithSkipDepth(1)) } -func comparePrimitives(t Ydb.Type_PrimitiveTypeId, l *Ydb.Value, r *Ydb.Value) (int, error) { - _, lIsNull := l.Value.(*Ydb.Value_NullFlagValue) - _, rIsNull := r.Value.(*Ydb.Value_NullFlagValue) +func comparePrimitives(t Ydb.Type_PrimitiveTypeId, lhs, rhs *Ydb.Value) (int, error) { + _, lIsNull := lhs.Value.(*Ydb.Value_NullFlagValue) + _, rIsNull := rhs.Value.(*Ydb.Value_NullFlagValue) if lIsNull { if rIsNull { return 0, nil @@ -112,24 +112,24 @@ func comparePrimitives(t Ydb.Type_PrimitiveTypeId, l *Ydb.Value, r *Ydb.Value) ( } if compare, found := comparators[t]; found { - return compare(l, r), nil + return compare(lhs, rhs), nil } // special cases switch t { case Ydb.Type_DYNUMBER: - return compareDyNumber(l, r) + return compareDyNumber(lhs, rhs) default: - return 0, notComparableError(l, r) + return 0, notComparableError(lhs, rhs) } } -func compareTuplesOrLists(l []*Ydb.TypedValue, r []*Ydb.TypedValue) (int, error) { - for i, lval := range l { - if i >= len(r) { - // l is longer than r, first len(r) elements equal +func compareTuplesOrLists(lhs, rhs []*Ydb.TypedValue) (int, error) { + for i, lval := range lhs { + if i >= len(rhs) { + // lhs is longer than rhs, first len(rhs) elements equal return 1, nil } - rval := r[i] + rval := rhs[i] cmp, err := compare(lval, rval) if err != nil { return 0, xerrors.WithStackTrace(err) @@ -138,20 +138,20 @@ func compareTuplesOrLists(l []*Ydb.TypedValue, r []*Ydb.TypedValue) (int, error) return cmp, nil } } - // len(l) elements equal - if len(r) > len(l) { + // len(lhs) elements equal + if len(rhs) > len(lhs) { return -1, nil } return 0, nil } -func compareStructs(l []*Ydb.TypedValue, r []*Ydb.TypedValue) (int, error) { - for i, lval := range l { - if i >= len(r) { - // l is longer than r, first len(r) elements equal +func compareStructs(lhs, rhs []*Ydb.TypedValue) (int, error) { + for i, lval := range lhs { + if i >= len(rhs) { + // lhs is longer than rhs, first len(rhs) elements equal return 1, nil } - rval := r[i] + rval := rhs[i] cmp, err := compare(lval, rval) if err != nil { return 0, xerrors.WithStackTrace(err) @@ -160,8 +160,8 @@ func compareStructs(l []*Ydb.TypedValue, r []*Ydb.TypedValue) (int, error) { return cmp, nil } } - // len(l) elements equal - if len(r) > len(l) { + // len(lhs) elements equal + if len(rhs) > len(lhs) { return -1, nil } return 0, nil diff --git a/topic/topicoptions/topicoptions_reader.go b/topic/topicoptions/topicoptions_reader.go index bb9ddd7d6..0d1b58dd0 100644 --- a/topic/topicoptions/topicoptions_reader.go +++ b/topic/topicoptions/topicoptions_reader.go @@ -254,9 +254,9 @@ func WithGetPartitionStartOffset(f GetPartitionStartOffsetFunc) ReaderOption { // # Experimental // // Notice: This API is EXPERIMENTAL and may be changed or removed in a later release. -func WithReaderTrace(tracer trace.Topic) ReaderOption { +func WithReaderTrace(t trace.Topic) ReaderOption { //nolint:gocritic return func(cfg *topicreaderinternal.ReaderConfig) { - cfg.Tracer = cfg.Tracer.Compose(&tracer) + cfg.Trace = cfg.Trace.Compose(&t) } } diff --git a/topic/topicoptions/topicoptions_topic.go b/topic/topicoptions/topicoptions_topic.go index 1afeed271..f79b710e2 100644 --- a/topic/topicoptions/topicoptions_topic.go +++ b/topic/topicoptions/topicoptions_topic.go @@ -20,7 +20,7 @@ type TopicOption func(c *topic.Config) // # Experimental // // Notice: This API is EXPERIMENTAL and may be changed or removed in a later release. -func WithTrace(trace trace.Topic, opts ...trace.TopicComposeOption) TopicOption { +func WithTrace(trace trace.Topic, opts ...trace.TopicComposeOption) TopicOption { //nolint:gocritic return func(c *topic.Config) { c.Trace = c.Trace.Compose(&trace, opts...) } diff --git a/topic/topicoptions/topicoptions_writer.go b/topic/topicoptions/topicoptions_writer.go index 62e495662..9f31b3be5 100644 --- a/topic/topicoptions/topicoptions_writer.go +++ b/topic/topicoptions/topicoptions_writer.go @@ -191,8 +191,8 @@ func WithWriterStartTimeout(timeout time.Duration) WriterOption { // # Experimental // // Notice: This API is EXPERIMENTAL and may be changed or removed in a later release. -func WithWriterTrace(tracer trace.Topic) WriterOption { - return topicwriterinternal.WithTrace(&tracer) +func WithWriterTrace(t trace.Topic) WriterOption { //nolint:gocritic + return topicwriterinternal.WithTrace(&t) } // WithWriterUpdateTokenInterval diff --git a/trace/topic.go b/trace/topic.go index 58161a248..5a6c8babc 100644 --- a/trace/topic.go +++ b/trace/topic.go @@ -1,4 +1,3 @@ -//nolint:lll package trace import ( @@ -18,37 +17,51 @@ type ( // later release. Topic struct { // TopicReaderStreamLifeCycleEvents - OnReaderReconnect func(startInfo TopicReaderReconnectStartInfo) func(doneInfo TopicReaderReconnectDoneInfo) - OnReaderReconnectRequest func(info TopicReaderReconnectRequestInfo) + OnReaderReconnect func(TopicReaderReconnectStartInfo) func(TopicReaderReconnectDoneInfo) + OnReaderReconnectRequest func(TopicReaderReconnectRequestInfo) // TopicReaderPartitionEvents - OnReaderPartitionReadStartResponse func(startInfo TopicReaderPartitionReadStartResponseStartInfo) func(doneInfo TopicReaderPartitionReadStartResponseDoneInfo) - OnReaderPartitionReadStopResponse func(startInfo TopicReaderPartitionReadStopResponseStartInfo) func(doneInfo TopicReaderPartitionReadStopResponseDoneInfo) + OnReaderPartitionReadStartResponse func( + TopicReaderPartitionReadStartResponseStartInfo, + ) func( + TopicReaderPartitionReadStartResponseDoneInfo, + ) + OnReaderPartitionReadStopResponse func( + TopicReaderPartitionReadStopResponseStartInfo, + ) func( + TopicReaderPartitionReadStopResponseDoneInfo, + ) // TopicReaderStreamEvents - OnReaderCommit func(startInfo TopicReaderCommitStartInfo) func(doneInfo TopicReaderCommitDoneInfo) - OnReaderSendCommitMessage func(startInfo TopicReaderSendCommitMessageStartInfo) func(doneInfo TopicReaderSendCommitMessageDoneInfo) - OnReaderCommittedNotify func(info TopicReaderCommittedNotifyInfo) - OnReaderClose func(startInfo TopicReaderCloseStartInfo) func(doneInfo TopicReaderCloseDoneInfo) - OnReaderInit func(startInfo TopicReaderInitStartInfo) func(doneInfo TopicReaderInitDoneInfo) - OnReaderError func(info TopicReaderErrorInfo) - OnReaderUpdateToken func(startInfo OnReadUpdateTokenStartInfo) func(updateTokenInfo OnReadUpdateTokenMiddleTokenReceivedInfo) func(doneInfo OnReadStreamUpdateTokenDoneInfo) + OnReaderCommit func(TopicReaderCommitStartInfo) func(TopicReaderCommitDoneInfo) + OnReaderSendCommitMessage func(TopicReaderSendCommitMessageStartInfo) func(TopicReaderSendCommitMessageDoneInfo) + OnReaderCommittedNotify func(TopicReaderCommittedNotifyInfo) + OnReaderClose func(TopicReaderCloseStartInfo) func(TopicReaderCloseDoneInfo) + OnReaderInit func(TopicReaderInitStartInfo) func(TopicReaderInitDoneInfo) + OnReaderError func(TopicReaderErrorInfo) + OnReaderUpdateToken func( + OnReadUpdateTokenStartInfo, + ) func( + OnReadUpdateTokenMiddleTokenReceivedInfo, + ) func( + OnReadStreamUpdateTokenDoneInfo, + ) // TopicReaderMessageEvents - OnReaderSentDataRequest func(startInfo TopicReaderSentDataRequestInfo) - OnReaderReceiveDataResponse func(startInfo TopicReaderReceiveDataResponseStartInfo) func(doneInfo TopicReaderReceiveDataResponseDoneInfo) - OnReaderReadMessages func(startInfo TopicReaderReadMessagesStartInfo) func(doneInfo TopicReaderReadMessagesDoneInfo) - OnReaderUnknownGrpcMessage func(info OnReadUnknownGrpcMessageInfo) + OnReaderSentDataRequest func(TopicReaderSentDataRequestInfo) + OnReaderReceiveDataResponse func(TopicReaderReceiveDataResponseStartInfo) func(TopicReaderReceiveDataResponseDoneInfo) + OnReaderReadMessages func(TopicReaderReadMessagesStartInfo) func(TopicReaderReadMessagesDoneInfo) + OnReaderUnknownGrpcMessage func(OnReadUnknownGrpcMessageInfo) // TopicWriterStreamLifeCycleEvents - OnWriterReconnect func(startInfo TopicWriterReconnectStartInfo) func(doneInfo TopicWriterReconnectDoneInfo) - OnWriterInitStream func(startInfo TopicWriterInitStreamStartInfo) func(doneInfo TopicWriterInitStreamDoneInfo) - OnWriterClose func(startInfo TopicWriterCloseStartInfo) func(doneInfo TopicWriterCloseDoneInfo) + OnWriterReconnect func(TopicWriterReconnectStartInfo) func(TopicWriterReconnectDoneInfo) + OnWriterInitStream func(TopicWriterInitStreamStartInfo) func(TopicWriterInitStreamDoneInfo) + OnWriterClose func(TopicWriterCloseStartInfo) func(TopicWriterCloseDoneInfo) // TopicWriterStreamEvents - OnWriterCompressMessages func(startInfo TopicWriterCompressMessagesStartInfo) func(doneInfo TopicWriterCompressMessagesDoneInfo) - OnWriterSendMessages func(startInfo TopicWriterSendMessagesStartInfo) func(doneInfo TopicWriterSendMessagesDoneInfo) - OnWriterReadUnknownGrpcMessage func(info TopicOnWriterReadUnknownGrpcMessageInfo) + OnWriterCompressMessages func(TopicWriterCompressMessagesStartInfo) func(TopicWriterCompressMessagesDoneInfo) + OnWriterSendMessages func(TopicWriterSendMessagesStartInfo) func(TopicWriterSendMessagesDoneInfo) + OnWriterReadUnknownGrpcMessage func(TopicOnWriterReadUnknownGrpcMessageInfo) } // TopicReaderPartitionReadStartResponseStartInfo @@ -447,9 +460,9 @@ type ( type TopicWriterCompressMessagesReason string const ( - TopicWriterCompressMessagesReasonCompressData = TopicWriterCompressMessagesReason("compress-on-send") - TopicWriterCompressMessagesReasonCompressDataOnWriteReadData = TopicWriterCompressMessagesReason("compress-on-call-write") - TopicWriterCompressMessagesReasonCodecsMeasure = TopicWriterCompressMessagesReason("compress-on-codecs-measure") + TopicWriterCompressMessagesReasonCompressData = TopicWriterCompressMessagesReason("compress-on-send") //nolint:lll + TopicWriterCompressMessagesReasonCompressDataOnWriteReadData = TopicWriterCompressMessagesReason("compress-on-call-write") //nolint:lll + TopicWriterCompressMessagesReasonCodecsMeasure = TopicWriterCompressMessagesReason("compress-on-codecs-measure") //nolint:lll ) func (r TopicWriterCompressMessagesReason) String() string { diff --git a/trace/topic_gtrace.go b/trace/topic_gtrace.go index d254859b5..6a00c3b78 100644 --- a/trace/topic_gtrace.go +++ b/trace/topic_gtrace.go @@ -33,7 +33,7 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { { h1 := t.OnReaderReconnect h2 := x.OnReaderReconnect - ret.OnReaderReconnect = func(startInfo TopicReaderReconnectStartInfo) func(TopicReaderReconnectDoneInfo) { + ret.OnReaderReconnect = func(t TopicReaderReconnectStartInfo) func(TopicReaderReconnectDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -43,12 +43,12 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { } var r, r1 func(TopicReaderReconnectDoneInfo) if h1 != nil { - r = h1(startInfo) + r = h1(t) } if h2 != nil { - r1 = h2(startInfo) + r1 = h2(t) } - return func(doneInfo TopicReaderReconnectDoneInfo) { + return func(t TopicReaderReconnectDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -57,10 +57,10 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { }() } if r != nil { - r(doneInfo) + r(t) } if r1 != nil { - r1(doneInfo) + r1(t) } } } @@ -68,7 +68,7 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { { h1 := t.OnReaderReconnectRequest h2 := x.OnReaderReconnectRequest - ret.OnReaderReconnectRequest = func(info TopicReaderReconnectRequestInfo) { + ret.OnReaderReconnectRequest = func(t TopicReaderReconnectRequestInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -77,17 +77,17 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { }() } if h1 != nil { - h1(info) + h1(t) } if h2 != nil { - h2(info) + h2(t) } } } { h1 := t.OnReaderPartitionReadStartResponse h2 := x.OnReaderPartitionReadStartResponse - ret.OnReaderPartitionReadStartResponse = func(startInfo TopicReaderPartitionReadStartResponseStartInfo) func(TopicReaderPartitionReadStartResponseDoneInfo) { + ret.OnReaderPartitionReadStartResponse = func(t TopicReaderPartitionReadStartResponseStartInfo) func(TopicReaderPartitionReadStartResponseDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -97,12 +97,12 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { } var r, r1 func(TopicReaderPartitionReadStartResponseDoneInfo) if h1 != nil { - r = h1(startInfo) + r = h1(t) } if h2 != nil { - r1 = h2(startInfo) + r1 = h2(t) } - return func(doneInfo TopicReaderPartitionReadStartResponseDoneInfo) { + return func(t TopicReaderPartitionReadStartResponseDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -111,10 +111,10 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { }() } if r != nil { - r(doneInfo) + r(t) } if r1 != nil { - r1(doneInfo) + r1(t) } } } @@ -122,7 +122,7 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { { h1 := t.OnReaderPartitionReadStopResponse h2 := x.OnReaderPartitionReadStopResponse - ret.OnReaderPartitionReadStopResponse = func(startInfo TopicReaderPartitionReadStopResponseStartInfo) func(TopicReaderPartitionReadStopResponseDoneInfo) { + ret.OnReaderPartitionReadStopResponse = func(t TopicReaderPartitionReadStopResponseStartInfo) func(TopicReaderPartitionReadStopResponseDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -132,12 +132,12 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { } var r, r1 func(TopicReaderPartitionReadStopResponseDoneInfo) if h1 != nil { - r = h1(startInfo) + r = h1(t) } if h2 != nil { - r1 = h2(startInfo) + r1 = h2(t) } - return func(doneInfo TopicReaderPartitionReadStopResponseDoneInfo) { + return func(t TopicReaderPartitionReadStopResponseDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -146,10 +146,10 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { }() } if r != nil { - r(doneInfo) + r(t) } if r1 != nil { - r1(doneInfo) + r1(t) } } } @@ -157,7 +157,7 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { { h1 := t.OnReaderCommit h2 := x.OnReaderCommit - ret.OnReaderCommit = func(startInfo TopicReaderCommitStartInfo) func(TopicReaderCommitDoneInfo) { + ret.OnReaderCommit = func(t TopicReaderCommitStartInfo) func(TopicReaderCommitDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -167,12 +167,12 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { } var r, r1 func(TopicReaderCommitDoneInfo) if h1 != nil { - r = h1(startInfo) + r = h1(t) } if h2 != nil { - r1 = h2(startInfo) + r1 = h2(t) } - return func(doneInfo TopicReaderCommitDoneInfo) { + return func(t TopicReaderCommitDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -181,10 +181,10 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { }() } if r != nil { - r(doneInfo) + r(t) } if r1 != nil { - r1(doneInfo) + r1(t) } } } @@ -192,7 +192,7 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { { h1 := t.OnReaderSendCommitMessage h2 := x.OnReaderSendCommitMessage - ret.OnReaderSendCommitMessage = func(startInfo TopicReaderSendCommitMessageStartInfo) func(TopicReaderSendCommitMessageDoneInfo) { + ret.OnReaderSendCommitMessage = func(t TopicReaderSendCommitMessageStartInfo) func(TopicReaderSendCommitMessageDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -202,12 +202,12 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { } var r, r1 func(TopicReaderSendCommitMessageDoneInfo) if h1 != nil { - r = h1(startInfo) + r = h1(t) } if h2 != nil { - r1 = h2(startInfo) + r1 = h2(t) } - return func(doneInfo TopicReaderSendCommitMessageDoneInfo) { + return func(t TopicReaderSendCommitMessageDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -216,10 +216,10 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { }() } if r != nil { - r(doneInfo) + r(t) } if r1 != nil { - r1(doneInfo) + r1(t) } } } @@ -227,7 +227,7 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { { h1 := t.OnReaderCommittedNotify h2 := x.OnReaderCommittedNotify - ret.OnReaderCommittedNotify = func(info TopicReaderCommittedNotifyInfo) { + ret.OnReaderCommittedNotify = func(t TopicReaderCommittedNotifyInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -236,17 +236,17 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { }() } if h1 != nil { - h1(info) + h1(t) } if h2 != nil { - h2(info) + h2(t) } } } { h1 := t.OnReaderClose h2 := x.OnReaderClose - ret.OnReaderClose = func(startInfo TopicReaderCloseStartInfo) func(TopicReaderCloseDoneInfo) { + ret.OnReaderClose = func(t TopicReaderCloseStartInfo) func(TopicReaderCloseDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -256,12 +256,12 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { } var r, r1 func(TopicReaderCloseDoneInfo) if h1 != nil { - r = h1(startInfo) + r = h1(t) } if h2 != nil { - r1 = h2(startInfo) + r1 = h2(t) } - return func(doneInfo TopicReaderCloseDoneInfo) { + return func(t TopicReaderCloseDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -270,10 +270,10 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { }() } if r != nil { - r(doneInfo) + r(t) } if r1 != nil { - r1(doneInfo) + r1(t) } } } @@ -281,7 +281,7 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { { h1 := t.OnReaderInit h2 := x.OnReaderInit - ret.OnReaderInit = func(startInfo TopicReaderInitStartInfo) func(TopicReaderInitDoneInfo) { + ret.OnReaderInit = func(t TopicReaderInitStartInfo) func(TopicReaderInitDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -291,12 +291,12 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { } var r, r1 func(TopicReaderInitDoneInfo) if h1 != nil { - r = h1(startInfo) + r = h1(t) } if h2 != nil { - r1 = h2(startInfo) + r1 = h2(t) } - return func(doneInfo TopicReaderInitDoneInfo) { + return func(t TopicReaderInitDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -305,10 +305,10 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { }() } if r != nil { - r(doneInfo) + r(t) } if r1 != nil { - r1(doneInfo) + r1(t) } } } @@ -316,7 +316,7 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { { h1 := t.OnReaderError h2 := x.OnReaderError - ret.OnReaderError = func(info TopicReaderErrorInfo) { + ret.OnReaderError = func(t TopicReaderErrorInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -325,17 +325,17 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { }() } if h1 != nil { - h1(info) + h1(t) } if h2 != nil { - h2(info) + h2(t) } } } { h1 := t.OnReaderUpdateToken h2 := x.OnReaderUpdateToken - ret.OnReaderUpdateToken = func(startInfo OnReadUpdateTokenStartInfo) func(OnReadUpdateTokenMiddleTokenReceivedInfo) func(OnReadStreamUpdateTokenDoneInfo) { + ret.OnReaderUpdateToken = func(o OnReadUpdateTokenStartInfo) func(OnReadUpdateTokenMiddleTokenReceivedInfo) func(OnReadStreamUpdateTokenDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -345,12 +345,12 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { } var r, r1 func(OnReadUpdateTokenMiddleTokenReceivedInfo) func(OnReadStreamUpdateTokenDoneInfo) if h1 != nil { - r = h1(startInfo) + r = h1(o) } if h2 != nil { - r1 = h2(startInfo) + r1 = h2(o) } - return func(updateTokenInfo OnReadUpdateTokenMiddleTokenReceivedInfo) func(OnReadStreamUpdateTokenDoneInfo) { + return func(o OnReadUpdateTokenMiddleTokenReceivedInfo) func(OnReadStreamUpdateTokenDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -360,12 +360,12 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { } var r2, r3 func(OnReadStreamUpdateTokenDoneInfo) if r != nil { - r2 = r(updateTokenInfo) + r2 = r(o) } if r1 != nil { - r3 = r1(updateTokenInfo) + r3 = r1(o) } - return func(doneInfo OnReadStreamUpdateTokenDoneInfo) { + return func(o OnReadStreamUpdateTokenDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -374,10 +374,10 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { }() } if r2 != nil { - r2(doneInfo) + r2(o) } if r3 != nil { - r3(doneInfo) + r3(o) } } } @@ -386,7 +386,7 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { { h1 := t.OnReaderSentDataRequest h2 := x.OnReaderSentDataRequest - ret.OnReaderSentDataRequest = func(startInfo TopicReaderSentDataRequestInfo) { + ret.OnReaderSentDataRequest = func(t TopicReaderSentDataRequestInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -395,17 +395,17 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { }() } if h1 != nil { - h1(startInfo) + h1(t) } if h2 != nil { - h2(startInfo) + h2(t) } } } { h1 := t.OnReaderReceiveDataResponse h2 := x.OnReaderReceiveDataResponse - ret.OnReaderReceiveDataResponse = func(startInfo TopicReaderReceiveDataResponseStartInfo) func(TopicReaderReceiveDataResponseDoneInfo) { + ret.OnReaderReceiveDataResponse = func(t TopicReaderReceiveDataResponseStartInfo) func(TopicReaderReceiveDataResponseDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -415,12 +415,12 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { } var r, r1 func(TopicReaderReceiveDataResponseDoneInfo) if h1 != nil { - r = h1(startInfo) + r = h1(t) } if h2 != nil { - r1 = h2(startInfo) + r1 = h2(t) } - return func(doneInfo TopicReaderReceiveDataResponseDoneInfo) { + return func(t TopicReaderReceiveDataResponseDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -429,10 +429,10 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { }() } if r != nil { - r(doneInfo) + r(t) } if r1 != nil { - r1(doneInfo) + r1(t) } } } @@ -440,7 +440,7 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { { h1 := t.OnReaderReadMessages h2 := x.OnReaderReadMessages - ret.OnReaderReadMessages = func(startInfo TopicReaderReadMessagesStartInfo) func(TopicReaderReadMessagesDoneInfo) { + ret.OnReaderReadMessages = func(t TopicReaderReadMessagesStartInfo) func(TopicReaderReadMessagesDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -450,12 +450,12 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { } var r, r1 func(TopicReaderReadMessagesDoneInfo) if h1 != nil { - r = h1(startInfo) + r = h1(t) } if h2 != nil { - r1 = h2(startInfo) + r1 = h2(t) } - return func(doneInfo TopicReaderReadMessagesDoneInfo) { + return func(t TopicReaderReadMessagesDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -464,10 +464,10 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { }() } if r != nil { - r(doneInfo) + r(t) } if r1 != nil { - r1(doneInfo) + r1(t) } } } @@ -475,7 +475,7 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { { h1 := t.OnReaderUnknownGrpcMessage h2 := x.OnReaderUnknownGrpcMessage - ret.OnReaderUnknownGrpcMessage = func(info OnReadUnknownGrpcMessageInfo) { + ret.OnReaderUnknownGrpcMessage = func(o OnReadUnknownGrpcMessageInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -484,17 +484,17 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { }() } if h1 != nil { - h1(info) + h1(o) } if h2 != nil { - h2(info) + h2(o) } } } { h1 := t.OnWriterReconnect h2 := x.OnWriterReconnect - ret.OnWriterReconnect = func(startInfo TopicWriterReconnectStartInfo) func(TopicWriterReconnectDoneInfo) { + ret.OnWriterReconnect = func(t TopicWriterReconnectStartInfo) func(TopicWriterReconnectDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -504,12 +504,12 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { } var r, r1 func(TopicWriterReconnectDoneInfo) if h1 != nil { - r = h1(startInfo) + r = h1(t) } if h2 != nil { - r1 = h2(startInfo) + r1 = h2(t) } - return func(doneInfo TopicWriterReconnectDoneInfo) { + return func(t TopicWriterReconnectDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -518,10 +518,10 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { }() } if r != nil { - r(doneInfo) + r(t) } if r1 != nil { - r1(doneInfo) + r1(t) } } } @@ -529,7 +529,7 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { { h1 := t.OnWriterInitStream h2 := x.OnWriterInitStream - ret.OnWriterInitStream = func(startInfo TopicWriterInitStreamStartInfo) func(TopicWriterInitStreamDoneInfo) { + ret.OnWriterInitStream = func(t TopicWriterInitStreamStartInfo) func(TopicWriterInitStreamDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -539,12 +539,12 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { } var r, r1 func(TopicWriterInitStreamDoneInfo) if h1 != nil { - r = h1(startInfo) + r = h1(t) } if h2 != nil { - r1 = h2(startInfo) + r1 = h2(t) } - return func(doneInfo TopicWriterInitStreamDoneInfo) { + return func(t TopicWriterInitStreamDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -553,10 +553,10 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { }() } if r != nil { - r(doneInfo) + r(t) } if r1 != nil { - r1(doneInfo) + r1(t) } } } @@ -564,7 +564,7 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { { h1 := t.OnWriterClose h2 := x.OnWriterClose - ret.OnWriterClose = func(startInfo TopicWriterCloseStartInfo) func(TopicWriterCloseDoneInfo) { + ret.OnWriterClose = func(t TopicWriterCloseStartInfo) func(TopicWriterCloseDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -574,12 +574,12 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { } var r, r1 func(TopicWriterCloseDoneInfo) if h1 != nil { - r = h1(startInfo) + r = h1(t) } if h2 != nil { - r1 = h2(startInfo) + r1 = h2(t) } - return func(doneInfo TopicWriterCloseDoneInfo) { + return func(t TopicWriterCloseDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -588,10 +588,10 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { }() } if r != nil { - r(doneInfo) + r(t) } if r1 != nil { - r1(doneInfo) + r1(t) } } } @@ -599,7 +599,7 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { { h1 := t.OnWriterCompressMessages h2 := x.OnWriterCompressMessages - ret.OnWriterCompressMessages = func(startInfo TopicWriterCompressMessagesStartInfo) func(TopicWriterCompressMessagesDoneInfo) { + ret.OnWriterCompressMessages = func(t TopicWriterCompressMessagesStartInfo) func(TopicWriterCompressMessagesDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -609,12 +609,12 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { } var r, r1 func(TopicWriterCompressMessagesDoneInfo) if h1 != nil { - r = h1(startInfo) + r = h1(t) } if h2 != nil { - r1 = h2(startInfo) + r1 = h2(t) } - return func(doneInfo TopicWriterCompressMessagesDoneInfo) { + return func(t TopicWriterCompressMessagesDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -623,10 +623,10 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { }() } if r != nil { - r(doneInfo) + r(t) } if r1 != nil { - r1(doneInfo) + r1(t) } } } @@ -634,7 +634,7 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { { h1 := t.OnWriterSendMessages h2 := x.OnWriterSendMessages - ret.OnWriterSendMessages = func(startInfo TopicWriterSendMessagesStartInfo) func(TopicWriterSendMessagesDoneInfo) { + ret.OnWriterSendMessages = func(t TopicWriterSendMessagesStartInfo) func(TopicWriterSendMessagesDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -644,12 +644,12 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { } var r, r1 func(TopicWriterSendMessagesDoneInfo) if h1 != nil { - r = h1(startInfo) + r = h1(t) } if h2 != nil { - r1 = h2(startInfo) + r1 = h2(t) } - return func(doneInfo TopicWriterSendMessagesDoneInfo) { + return func(t TopicWriterSendMessagesDoneInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -658,10 +658,10 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { }() } if r != nil { - r(doneInfo) + r(t) } if r1 != nil { - r1(doneInfo) + r1(t) } } } @@ -669,7 +669,7 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { { h1 := t.OnWriterReadUnknownGrpcMessage h2 := x.OnWriterReadUnknownGrpcMessage - ret.OnWriterReadUnknownGrpcMessage = func(info TopicOnWriterReadUnknownGrpcMessageInfo) { + ret.OnWriterReadUnknownGrpcMessage = func(t TopicOnWriterReadUnknownGrpcMessageInfo) { if options.panicCallback != nil { defer func() { if e := recover(); e != nil { @@ -678,23 +678,23 @@ func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { }() } if h1 != nil { - h1(info) + h1(t) } if h2 != nil { - h2(info) + h2(t) } } } return &ret } -func (t *Topic) onReaderReconnect(startInfo TopicReaderReconnectStartInfo) func(doneInfo TopicReaderReconnectDoneInfo) { +func (t *Topic) onReaderReconnect(t1 TopicReaderReconnectStartInfo) func(TopicReaderReconnectDoneInfo) { fn := t.OnReaderReconnect if fn == nil { return func(TopicReaderReconnectDoneInfo) { return } } - res := fn(startInfo) + res := fn(t1) if res == nil { return func(TopicReaderReconnectDoneInfo) { return @@ -702,21 +702,21 @@ func (t *Topic) onReaderReconnect(startInfo TopicReaderReconnectStartInfo) func( } return res } -func (t *Topic) onReaderReconnectRequest(info TopicReaderReconnectRequestInfo) { +func (t *Topic) onReaderReconnectRequest(t1 TopicReaderReconnectRequestInfo) { fn := t.OnReaderReconnectRequest if fn == nil { return } - fn(info) + fn(t1) } -func (t *Topic) onReaderPartitionReadStartResponse(startInfo TopicReaderPartitionReadStartResponseStartInfo) func(doneInfo TopicReaderPartitionReadStartResponseDoneInfo) { +func (t *Topic) onReaderPartitionReadStartResponse(t1 TopicReaderPartitionReadStartResponseStartInfo) func(TopicReaderPartitionReadStartResponseDoneInfo) { fn := t.OnReaderPartitionReadStartResponse if fn == nil { return func(TopicReaderPartitionReadStartResponseDoneInfo) { return } } - res := fn(startInfo) + res := fn(t1) if res == nil { return func(TopicReaderPartitionReadStartResponseDoneInfo) { return @@ -724,14 +724,14 @@ func (t *Topic) onReaderPartitionReadStartResponse(startInfo TopicReaderPartitio } return res } -func (t *Topic) onReaderPartitionReadStopResponse(startInfo TopicReaderPartitionReadStopResponseStartInfo) func(doneInfo TopicReaderPartitionReadStopResponseDoneInfo) { +func (t *Topic) onReaderPartitionReadStopResponse(t1 TopicReaderPartitionReadStopResponseStartInfo) func(TopicReaderPartitionReadStopResponseDoneInfo) { fn := t.OnReaderPartitionReadStopResponse if fn == nil { return func(TopicReaderPartitionReadStopResponseDoneInfo) { return } } - res := fn(startInfo) + res := fn(t1) if res == nil { return func(TopicReaderPartitionReadStopResponseDoneInfo) { return @@ -739,14 +739,14 @@ func (t *Topic) onReaderPartitionReadStopResponse(startInfo TopicReaderPartition } return res } -func (t *Topic) onReaderCommit(startInfo TopicReaderCommitStartInfo) func(doneInfo TopicReaderCommitDoneInfo) { +func (t *Topic) onReaderCommit(t1 TopicReaderCommitStartInfo) func(TopicReaderCommitDoneInfo) { fn := t.OnReaderCommit if fn == nil { return func(TopicReaderCommitDoneInfo) { return } } - res := fn(startInfo) + res := fn(t1) if res == nil { return func(TopicReaderCommitDoneInfo) { return @@ -754,14 +754,14 @@ func (t *Topic) onReaderCommit(startInfo TopicReaderCommitStartInfo) func(doneIn } return res } -func (t *Topic) onReaderSendCommitMessage(startInfo TopicReaderSendCommitMessageStartInfo) func(doneInfo TopicReaderSendCommitMessageDoneInfo) { +func (t *Topic) onReaderSendCommitMessage(t1 TopicReaderSendCommitMessageStartInfo) func(TopicReaderSendCommitMessageDoneInfo) { fn := t.OnReaderSendCommitMessage if fn == nil { return func(TopicReaderSendCommitMessageDoneInfo) { return } } - res := fn(startInfo) + res := fn(t1) if res == nil { return func(TopicReaderSendCommitMessageDoneInfo) { return @@ -769,21 +769,21 @@ func (t *Topic) onReaderSendCommitMessage(startInfo TopicReaderSendCommitMessage } return res } -func (t *Topic) onReaderCommittedNotify(info TopicReaderCommittedNotifyInfo) { +func (t *Topic) onReaderCommittedNotify(t1 TopicReaderCommittedNotifyInfo) { fn := t.OnReaderCommittedNotify if fn == nil { return } - fn(info) + fn(t1) } -func (t *Topic) onReaderClose(startInfo TopicReaderCloseStartInfo) func(doneInfo TopicReaderCloseDoneInfo) { +func (t *Topic) onReaderClose(t1 TopicReaderCloseStartInfo) func(TopicReaderCloseDoneInfo) { fn := t.OnReaderClose if fn == nil { return func(TopicReaderCloseDoneInfo) { return } } - res := fn(startInfo) + res := fn(t1) if res == nil { return func(TopicReaderCloseDoneInfo) { return @@ -791,14 +791,14 @@ func (t *Topic) onReaderClose(startInfo TopicReaderCloseStartInfo) func(doneInfo } return res } -func (t *Topic) onReaderInit(startInfo TopicReaderInitStartInfo) func(doneInfo TopicReaderInitDoneInfo) { +func (t *Topic) onReaderInit(t1 TopicReaderInitStartInfo) func(TopicReaderInitDoneInfo) { fn := t.OnReaderInit if fn == nil { return func(TopicReaderInitDoneInfo) { return } } - res := fn(startInfo) + res := fn(t1) if res == nil { return func(TopicReaderInitDoneInfo) { return @@ -806,14 +806,14 @@ func (t *Topic) onReaderInit(startInfo TopicReaderInitStartInfo) func(doneInfo T } return res } -func (t *Topic) onReaderError(info TopicReaderErrorInfo) { +func (t *Topic) onReaderError(t1 TopicReaderErrorInfo) { fn := t.OnReaderError if fn == nil { return } - fn(info) + fn(t1) } -func (t *Topic) onReaderUpdateToken(startInfo OnReadUpdateTokenStartInfo) func(updateTokenInfo OnReadUpdateTokenMiddleTokenReceivedInfo) func(doneInfo OnReadStreamUpdateTokenDoneInfo) { +func (t *Topic) onReaderUpdateToken(o OnReadUpdateTokenStartInfo) func(OnReadUpdateTokenMiddleTokenReceivedInfo) func(OnReadStreamUpdateTokenDoneInfo) { fn := t.OnReaderUpdateToken if fn == nil { return func(OnReadUpdateTokenMiddleTokenReceivedInfo) func(OnReadStreamUpdateTokenDoneInfo) { @@ -822,7 +822,7 @@ func (t *Topic) onReaderUpdateToken(startInfo OnReadUpdateTokenStartInfo) func(u } } } - res := fn(startInfo) + res := fn(o) if res == nil { return func(OnReadUpdateTokenMiddleTokenReceivedInfo) func(OnReadStreamUpdateTokenDoneInfo) { return func(OnReadStreamUpdateTokenDoneInfo) { @@ -830,8 +830,8 @@ func (t *Topic) onReaderUpdateToken(startInfo OnReadUpdateTokenStartInfo) func(u } } } - return func(updateTokenInfo OnReadUpdateTokenMiddleTokenReceivedInfo) func(OnReadStreamUpdateTokenDoneInfo) { - res := res(updateTokenInfo) + return func(o OnReadUpdateTokenMiddleTokenReceivedInfo) func(OnReadStreamUpdateTokenDoneInfo) { + res := res(o) if res == nil { return func(OnReadStreamUpdateTokenDoneInfo) { return @@ -840,21 +840,21 @@ func (t *Topic) onReaderUpdateToken(startInfo OnReadUpdateTokenStartInfo) func(u return res } } -func (t *Topic) onReaderSentDataRequest(startInfo TopicReaderSentDataRequestInfo) { +func (t *Topic) onReaderSentDataRequest(t1 TopicReaderSentDataRequestInfo) { fn := t.OnReaderSentDataRequest if fn == nil { return } - fn(startInfo) + fn(t1) } -func (t *Topic) onReaderReceiveDataResponse(startInfo TopicReaderReceiveDataResponseStartInfo) func(doneInfo TopicReaderReceiveDataResponseDoneInfo) { +func (t *Topic) onReaderReceiveDataResponse(t1 TopicReaderReceiveDataResponseStartInfo) func(TopicReaderReceiveDataResponseDoneInfo) { fn := t.OnReaderReceiveDataResponse if fn == nil { return func(TopicReaderReceiveDataResponseDoneInfo) { return } } - res := fn(startInfo) + res := fn(t1) if res == nil { return func(TopicReaderReceiveDataResponseDoneInfo) { return @@ -862,14 +862,14 @@ func (t *Topic) onReaderReceiveDataResponse(startInfo TopicReaderReceiveDataResp } return res } -func (t *Topic) onReaderReadMessages(startInfo TopicReaderReadMessagesStartInfo) func(doneInfo TopicReaderReadMessagesDoneInfo) { +func (t *Topic) onReaderReadMessages(t1 TopicReaderReadMessagesStartInfo) func(TopicReaderReadMessagesDoneInfo) { fn := t.OnReaderReadMessages if fn == nil { return func(TopicReaderReadMessagesDoneInfo) { return } } - res := fn(startInfo) + res := fn(t1) if res == nil { return func(TopicReaderReadMessagesDoneInfo) { return @@ -877,21 +877,21 @@ func (t *Topic) onReaderReadMessages(startInfo TopicReaderReadMessagesStartInfo) } return res } -func (t *Topic) onReaderUnknownGrpcMessage(info OnReadUnknownGrpcMessageInfo) { +func (t *Topic) onReaderUnknownGrpcMessage(o OnReadUnknownGrpcMessageInfo) { fn := t.OnReaderUnknownGrpcMessage if fn == nil { return } - fn(info) + fn(o) } -func (t *Topic) onWriterReconnect(startInfo TopicWriterReconnectStartInfo) func(doneInfo TopicWriterReconnectDoneInfo) { +func (t *Topic) onWriterReconnect(t1 TopicWriterReconnectStartInfo) func(TopicWriterReconnectDoneInfo) { fn := t.OnWriterReconnect if fn == nil { return func(TopicWriterReconnectDoneInfo) { return } } - res := fn(startInfo) + res := fn(t1) if res == nil { return func(TopicWriterReconnectDoneInfo) { return @@ -899,14 +899,14 @@ func (t *Topic) onWriterReconnect(startInfo TopicWriterReconnectStartInfo) func( } return res } -func (t *Topic) onWriterInitStream(startInfo TopicWriterInitStreamStartInfo) func(doneInfo TopicWriterInitStreamDoneInfo) { +func (t *Topic) onWriterInitStream(t1 TopicWriterInitStreamStartInfo) func(TopicWriterInitStreamDoneInfo) { fn := t.OnWriterInitStream if fn == nil { return func(TopicWriterInitStreamDoneInfo) { return } } - res := fn(startInfo) + res := fn(t1) if res == nil { return func(TopicWriterInitStreamDoneInfo) { return @@ -914,14 +914,14 @@ func (t *Topic) onWriterInitStream(startInfo TopicWriterInitStreamStartInfo) fun } return res } -func (t *Topic) onWriterClose(startInfo TopicWriterCloseStartInfo) func(doneInfo TopicWriterCloseDoneInfo) { +func (t *Topic) onWriterClose(t1 TopicWriterCloseStartInfo) func(TopicWriterCloseDoneInfo) { fn := t.OnWriterClose if fn == nil { return func(TopicWriterCloseDoneInfo) { return } } - res := fn(startInfo) + res := fn(t1) if res == nil { return func(TopicWriterCloseDoneInfo) { return @@ -929,14 +929,14 @@ func (t *Topic) onWriterClose(startInfo TopicWriterCloseStartInfo) func(doneInfo } return res } -func (t *Topic) onWriterCompressMessages(startInfo TopicWriterCompressMessagesStartInfo) func(doneInfo TopicWriterCompressMessagesDoneInfo) { +func (t *Topic) onWriterCompressMessages(t1 TopicWriterCompressMessagesStartInfo) func(TopicWriterCompressMessagesDoneInfo) { fn := t.OnWriterCompressMessages if fn == nil { return func(TopicWriterCompressMessagesDoneInfo) { return } } - res := fn(startInfo) + res := fn(t1) if res == nil { return func(TopicWriterCompressMessagesDoneInfo) { return @@ -944,14 +944,14 @@ func (t *Topic) onWriterCompressMessages(startInfo TopicWriterCompressMessagesSt } return res } -func (t *Topic) onWriterSendMessages(startInfo TopicWriterSendMessagesStartInfo) func(doneInfo TopicWriterSendMessagesDoneInfo) { +func (t *Topic) onWriterSendMessages(t1 TopicWriterSendMessagesStartInfo) func(TopicWriterSendMessagesDoneInfo) { fn := t.OnWriterSendMessages if fn == nil { return func(TopicWriterSendMessagesDoneInfo) { return } } - res := fn(startInfo) + res := fn(t1) if res == nil { return func(TopicWriterSendMessagesDoneInfo) { return @@ -959,12 +959,12 @@ func (t *Topic) onWriterSendMessages(startInfo TopicWriterSendMessagesStartInfo) } return res } -func (t *Topic) onWriterReadUnknownGrpcMessage(info TopicOnWriterReadUnknownGrpcMessageInfo) { +func (t *Topic) onWriterReadUnknownGrpcMessage(t1 TopicOnWriterReadUnknownGrpcMessageInfo) { fn := t.OnWriterReadUnknownGrpcMessage if fn == nil { return } - fn(info) + fn(t1) } func TopicOnReaderReconnect(t *Topic) func(error) { var p TopicReaderReconnectStartInfo