From 04e78b0faf3cf29a29cf39ddfa614d8900767fcc Mon Sep 17 00:00:00 2001 From: Purnesh Dixit Date: Mon, 16 Sep 2024 09:09:49 +0530 Subject: [PATCH] .*: fix lint issues of not having comments for exported funcs and vars along with any remaining issues and enable remaining disabled rules (#7575) * .*: fix lint issues of not having comments for exported funcs and vars along with any remaining issues and enable remaining disabled rules --- balancer/endpointsharding/endpointsharding.go | 5 +++ balancer/pickfirst/pickfirst.go | 3 ++ .../tls/certprovider/pemfile/builder.go | 1 + examples/features/advancedtls/client/main.go | 2 ++ examples/features/advancedtls/server/main.go | 2 ++ internal/balancer/gracefulswitch/config.go | 2 ++ internal/channelz/channel.go | 15 ++++++++ internal/channelz/server.go | 2 ++ internal/channelz/socket.go | 7 ++++ internal/channelz/subchannel.go | 2 ++ internal/channelz/trace.go | 19 +++++++--- internal/idle/idle.go | 2 ++ internal/internal.go | 2 ++ internal/stats/metrics_recorder_list.go | 10 ++++++ .../testutils/stats/test_metrics_recorder.go | 35 +++++++++++++++++++ internal/transport/transport.go | 9 +++++ mem/buffers.go | 26 ++++++++++---- rpc_util.go | 3 +- scripts/revive.toml | 13 +++---- security/advancedtls/advancedtls.go | 3 ++ 20 files changed, 141 insertions(+), 22 deletions(-) diff --git a/balancer/endpointsharding/endpointsharding.go b/balancer/endpointsharding/endpointsharding.go index 43d960df0af5..b8095e6f15e5 100644 --- a/balancer/endpointsharding/endpointsharding.go +++ b/balancer/endpointsharding/endpointsharding.go @@ -285,6 +285,11 @@ func (bw *balancerWrapper) UpdateState(state balancer.State) { bw.es.updateState() } +// ParseConfig parses a child config list and returns an LB config to use with +// the endpointsharding balancer. +// +// cfg is expected to be a JSON array of LB policy names + configs as the +// format of the loadBalancingConfig field in ServiceConfig. func ParseConfig(cfg json.RawMessage) (serviceconfig.LoadBalancingConfig, error) { return gracefulswitch.ParseConfig(cfg) } diff --git a/balancer/pickfirst/pickfirst.go b/balancer/pickfirst/pickfirst.go index 4d69b4052f8e..8fadf3dfcdd7 100644 --- a/balancer/pickfirst/pickfirst.go +++ b/balancer/pickfirst/pickfirst.go @@ -103,10 +103,13 @@ func (b *pickfirstBalancer) ResolverError(err error) { }) } +// Shuffler is an interface for shuffling an address list. type Shuffler interface { ShuffleAddressListForTesting(n int, swap func(i, j int)) } +// ShuffleAddressListForTesting pseudo-randomizes the order of addresses. n +// is the number of elements. swap swaps the elements with indexes i and j. func ShuffleAddressListForTesting(n int, swap func(i, j int)) { rand.Shuffle(n, swap) } func (b *pickfirstBalancer) UpdateClientConnState(state balancer.ClientConnState) error { diff --git a/credentials/tls/certprovider/pemfile/builder.go b/credentials/tls/certprovider/pemfile/builder.go index 8c15baeb59f6..ad4207892b7e 100644 --- a/credentials/tls/certprovider/pemfile/builder.go +++ b/credentials/tls/certprovider/pemfile/builder.go @@ -29,6 +29,7 @@ import ( ) const ( + // PluginName is the name of the PEM file watcher plugin. PluginName = "file_watcher" defaultRefreshInterval = 10 * time.Minute ) diff --git a/examples/features/advancedtls/client/main.go b/examples/features/advancedtls/client/main.go index a4cd98ca1a61..aaa9cf69a2f7 100644 --- a/examples/features/advancedtls/client/main.go +++ b/examples/features/advancedtls/client/main.go @@ -16,6 +16,8 @@ * */ +// Binary client is an example client demonstrating use of advancedtls, to set +// up a secure gRPC client connection with various TLS authentication methods. package main import ( diff --git a/examples/features/advancedtls/server/main.go b/examples/features/advancedtls/server/main.go index e22dc99930b7..d8b79a124b7a 100644 --- a/examples/features/advancedtls/server/main.go +++ b/examples/features/advancedtls/server/main.go @@ -16,6 +16,8 @@ * */ +// Binary server is an example client demonstrating how to set up a secure gRPC +// server using advancedtls. package main import ( diff --git a/internal/balancer/gracefulswitch/config.go b/internal/balancer/gracefulswitch/config.go index 13821a926606..85540f86a738 100644 --- a/internal/balancer/gracefulswitch/config.go +++ b/internal/balancer/gracefulswitch/config.go @@ -33,6 +33,8 @@ type lbConfig struct { childConfig serviceconfig.LoadBalancingConfig } +// ChildName returns the name of the child balancer of the gracefulswitch +// Balancer. func ChildName(l serviceconfig.LoadBalancingConfig) string { return l.(*lbConfig).childBuilder.Name() } diff --git a/internal/channelz/channel.go b/internal/channelz/channel.go index d7e9e1d54ecb..3ec662799a83 100644 --- a/internal/channelz/channel.go +++ b/internal/channelz/channel.go @@ -43,6 +43,8 @@ type Channel struct { // Non-zero traceRefCount means the trace of this channel cannot be deleted. traceRefCount int32 + // ChannelMetrics holds connectivity state, target and call metrics for the + // channel within channelz. ChannelMetrics ChannelMetrics } @@ -50,6 +52,8 @@ type Channel struct { // nesting. func (c *Channel) channelzIdentifier() {} +// String returns a string representation of the Channel, including its parent +// entity and ID. func (c *Channel) String() string { if c.Parent == nil { return fmt.Sprintf("Channel #%d", c.ID) @@ -61,24 +65,31 @@ func (c *Channel) id() int64 { return c.ID } +// SubChans returns a copy of the map of sub-channels associated with the +// Channel. func (c *Channel) SubChans() map[int64]string { db.mu.RLock() defer db.mu.RUnlock() return copyMap(c.subChans) } +// NestedChans returns a copy of the map of nested channels associated with the +// Channel. func (c *Channel) NestedChans() map[int64]string { db.mu.RLock() defer db.mu.RUnlock() return copyMap(c.nestedChans) } +// Trace returns a copy of the Channel's trace data. func (c *Channel) Trace() *ChannelTrace { db.mu.RLock() defer db.mu.RUnlock() return c.trace.copy() } +// ChannelMetrics holds connectivity state, target and call metrics for the +// channel within channelz. type ChannelMetrics struct { // The current connectivity state of the channel. State atomic.Pointer[connectivity.State] @@ -136,12 +147,16 @@ func strFromPointer(s *string) string { return *s } +// String returns a string representation of the ChannelMetrics, including its +// state, target, and call metrics. func (c *ChannelMetrics) String() string { return fmt.Sprintf("State: %v, Target: %s, CallsStarted: %v, CallsSucceeded: %v, CallsFailed: %v, LastCallStartedTimestamp: %v", c.State.Load(), strFromPointer(c.Target.Load()), c.CallsStarted.Load(), c.CallsSucceeded.Load(), c.CallsFailed.Load(), c.LastCallStartedTimestamp.Load(), ) } +// NewChannelMetricForTesting creates a new instance of ChannelMetrics with +// specified initial values for testing purposes. func NewChannelMetricForTesting(state connectivity.State, target string, started, succeeded, failed, timestamp int64) *ChannelMetrics { c := &ChannelMetrics{} c.State.Store(&state) diff --git a/internal/channelz/server.go b/internal/channelz/server.go index cdfc49d6eacc..b5a82499299d 100644 --- a/internal/channelz/server.go +++ b/internal/channelz/server.go @@ -59,6 +59,8 @@ func NewServerMetricsForTesting(started, succeeded, failed, timestamp int64) *Se return sm } +// CopyFrom copies the metrics data from the provided ServerMetrics +// instance into the current instance. func (sm *ServerMetrics) CopyFrom(o *ServerMetrics) { sm.CallsStarted.Store(o.CallsStarted.Load()) sm.CallsSucceeded.Store(o.CallsSucceeded.Load()) diff --git a/internal/channelz/socket.go b/internal/channelz/socket.go index fa64834b25d0..90103847c5f3 100644 --- a/internal/channelz/socket.go +++ b/internal/channelz/socket.go @@ -70,13 +70,18 @@ type EphemeralSocketMetrics struct { RemoteFlowControlWindow int64 } +// SocketType represents the type of socket. type SocketType string +// SocketType can be one of these. const ( SocketTypeNormal = "NormalSocket" SocketTypeListen = "ListenSocket" ) +// Socket represents a socket within channelz which includes socket +// metrics and data related to socket activity and provides methods +// for managing and interacting with sockets. type Socket struct { Entity SocketType SocketType @@ -100,6 +105,8 @@ type Socket struct { Security credentials.ChannelzSecurityValue } +// String returns a string representation of the Socket, including its parent +// entity, socket type, and ID. func (ls *Socket) String() string { return fmt.Sprintf("%s %s #%d", ls.Parent, ls.SocketType, ls.ID) } diff --git a/internal/channelz/subchannel.go b/internal/channelz/subchannel.go index 3b88e4cba8e1..b20802e6e960 100644 --- a/internal/channelz/subchannel.go +++ b/internal/channelz/subchannel.go @@ -47,12 +47,14 @@ func (sc *SubChannel) id() int64 { return sc.ID } +// Sockets returns a copy of the sockets map associated with the SubChannel. func (sc *SubChannel) Sockets() map[int64]string { db.mu.RLock() defer db.mu.RUnlock() return copyMap(sc.sockets) } +// Trace returns a copy of the ChannelTrace associated with the SubChannel. func (sc *SubChannel) Trace() *ChannelTrace { db.mu.RLock() defer db.mu.RUnlock() diff --git a/internal/channelz/trace.go b/internal/channelz/trace.go index 36b867403230..2bffe4777684 100644 --- a/internal/channelz/trace.go +++ b/internal/channelz/trace.go @@ -79,13 +79,21 @@ type TraceEvent struct { Parent *TraceEvent } +// ChannelTrace provides tracing information for a channel. +// It tracks various events and metadata related to the channel's lifecycle +// and operations. type ChannelTrace struct { - cm *channelMap - clearCalled bool + cm *channelMap + clearCalled bool + // The time when the trace was created. CreationTime time.Time - EventNum int64 - mu sync.Mutex - Events []*traceEvent + // A counter for the number of events recorded in the + // trace. + EventNum int64 + mu sync.Mutex + // A slice of traceEvent pointers representing the events recorded for + // this channel. + Events []*traceEvent } func (c *ChannelTrace) copy() *ChannelTrace { @@ -175,6 +183,7 @@ var refChannelTypeToString = map[RefChannelType]string{ RefNormalSocket: "NormalSocket", } +// String returns a string representation of the RefChannelType func (r RefChannelType) String() string { return refChannelTypeToString[r] } diff --git a/internal/idle/idle.go b/internal/idle/idle.go index fe49cb74c55a..5ef47e2e4dcb 100644 --- a/internal/idle/idle.go +++ b/internal/idle/idle.go @@ -182,6 +182,7 @@ func (m *Manager) tryEnterIdleMode() bool { return true } +// EnterIdleModeForTesting instructs the channel to enter idle mode. func (m *Manager) EnterIdleModeForTesting() { m.tryEnterIdleMode() } @@ -266,6 +267,7 @@ func (m *Manager) isClosed() bool { return atomic.LoadInt32(&m.closed) == 1 } +// Close stops the timer associated with the Manager, if it exists. func (m *Manager) Close() { atomic.StoreInt32(&m.closed, 1) diff --git a/internal/internal.go b/internal/internal.go index 7aae9240ffc0..84d605493595 100644 --- a/internal/internal.go +++ b/internal/internal.go @@ -191,6 +191,8 @@ var ( // ExitIdleModeForTesting gets the ClientConn to exit IDLE mode. ExitIdleModeForTesting any // func(*grpc.ClientConn) error + // ChannelzTurnOffForTesting disables the Channelz service for testing + // purposes. ChannelzTurnOffForTesting func() // TriggerXDSResourceNotFoundForTesting causes the provided xDS Client to diff --git a/internal/stats/metrics_recorder_list.go b/internal/stats/metrics_recorder_list.go index be110d41f9a4..79044657be15 100644 --- a/internal/stats/metrics_recorder_list.go +++ b/internal/stats/metrics_recorder_list.go @@ -54,6 +54,8 @@ func verifyLabels(desc *estats.MetricDescriptor, labelsRecv ...string) { } } +// RecordInt64Count records the measurement alongside labels on the int +// count associated with the provided handle. func (l *MetricsRecorderList) RecordInt64Count(handle *estats.Int64CountHandle, incr int64, labels ...string) { verifyLabels(handle.Descriptor(), labels...) @@ -62,6 +64,8 @@ func (l *MetricsRecorderList) RecordInt64Count(handle *estats.Int64CountHandle, } } +// RecordFloat64Count records the measurement alongside labels on the float +// count associated with the provided handle. func (l *MetricsRecorderList) RecordFloat64Count(handle *estats.Float64CountHandle, incr float64, labels ...string) { verifyLabels(handle.Descriptor(), labels...) @@ -70,6 +74,8 @@ func (l *MetricsRecorderList) RecordFloat64Count(handle *estats.Float64CountHand } } +// RecordInt64Histo records the measurement alongside labels on the int +// histo associated with the provided handle. func (l *MetricsRecorderList) RecordInt64Histo(handle *estats.Int64HistoHandle, incr int64, labels ...string) { verifyLabels(handle.Descriptor(), labels...) @@ -78,6 +84,8 @@ func (l *MetricsRecorderList) RecordInt64Histo(handle *estats.Int64HistoHandle, } } +// RecordFloat64Histo records the measurement alongside labels on the float +// histo associated with the provided handle. func (l *MetricsRecorderList) RecordFloat64Histo(handle *estats.Float64HistoHandle, incr float64, labels ...string) { verifyLabels(handle.Descriptor(), labels...) @@ -86,6 +94,8 @@ func (l *MetricsRecorderList) RecordFloat64Histo(handle *estats.Float64HistoHand } } +// RecordInt64Gauge records the measurement alongside labels on the int +// gauge associated with the provided handle. func (l *MetricsRecorderList) RecordInt64Gauge(handle *estats.Int64GaugeHandle, incr int64, labels ...string) { verifyLabels(handle.Descriptor(), labels...) diff --git a/internal/testutils/stats/test_metrics_recorder.go b/internal/testutils/stats/test_metrics_recorder.go index 93dda7ed2a3f..e8805dd8e65a 100644 --- a/internal/testutils/stats/test_metrics_recorder.go +++ b/internal/testutils/stats/test_metrics_recorder.go @@ -49,6 +49,7 @@ type TestMetricsRecorder struct { data map[estats.Metric]float64 } +// NewTestMetricsRecorder returns new TestMetricsRecorder func NewTestMetricsRecorder(t *testing.T) *TestMetricsRecorder { tmr := &TestMetricsRecorder{ t: t, @@ -97,6 +98,7 @@ func (r *TestMetricsRecorder) ClearMetrics() { r.data = make(map[estats.Metric]float64) } +// MetricsData represents data associated with a metric. type MetricsData struct { Handle *estats.MetricDescriptor @@ -109,6 +111,9 @@ type MetricsData struct { LabelVals []string } +// WaitForInt64Count waits for an int64 count metric to be recorded and +// verifies that the recorded metrics data matches the expected +// metricsDataWant. func (r *TestMetricsRecorder) WaitForInt64Count(ctx context.Context, metricsDataWant MetricsData) { got, err := r.intCountCh.Receive(ctx) if err != nil { @@ -120,6 +125,8 @@ func (r *TestMetricsRecorder) WaitForInt64Count(ctx context.Context, metricsData } } +// RecordInt64Count sends the metrics data to the intCountCh channel +// and updates the internal data map with the recorded value. func (r *TestMetricsRecorder) RecordInt64Count(handle *estats.Int64CountHandle, incr int64, labels ...string) { r.intCountCh.Send(MetricsData{ Handle: handle.Descriptor(), @@ -133,6 +140,9 @@ func (r *TestMetricsRecorder) RecordInt64Count(handle *estats.Int64CountHandle, r.data[handle.Name] = float64(incr) } +// WaitForFloat64Count waits for a float count metric to be recorded and +// verifies that the recorded metrics data matches the expected +// metricsDataWant. func (r *TestMetricsRecorder) WaitForFloat64Count(ctx context.Context, metricsDataWant MetricsData) { got, err := r.floatCountCh.Receive(ctx) if err != nil { @@ -144,6 +154,8 @@ func (r *TestMetricsRecorder) WaitForFloat64Count(ctx context.Context, metricsDa } } +// RecordFloat64Count sends the metrics data to the floatCountCh channel +// and updates the internal data map with the recorded value. func (r *TestMetricsRecorder) RecordFloat64Count(handle *estats.Float64CountHandle, incr float64, labels ...string) { r.floatCountCh.Send(MetricsData{ Handle: handle.Descriptor(), @@ -157,6 +169,8 @@ func (r *TestMetricsRecorder) RecordFloat64Count(handle *estats.Float64CountHand r.data[handle.Name] = incr } +// WaitForInt64Histo waits for an int histo metric to be recorded and verifies +// that the recorded metrics data matches the expected metricsDataWant. func (r *TestMetricsRecorder) WaitForInt64Histo(ctx context.Context, metricsDataWant MetricsData) { got, err := r.intHistoCh.Receive(ctx) if err != nil { @@ -168,6 +182,8 @@ func (r *TestMetricsRecorder) WaitForInt64Histo(ctx context.Context, metricsData } } +// RecordInt64Histo sends the metrics data to the intHistoCh channel +// and updates the internal data map with the recorded value. func (r *TestMetricsRecorder) RecordInt64Histo(handle *estats.Int64HistoHandle, incr int64, labels ...string) { r.intHistoCh.Send(MetricsData{ Handle: handle.Descriptor(), @@ -181,6 +197,9 @@ func (r *TestMetricsRecorder) RecordInt64Histo(handle *estats.Int64HistoHandle, r.data[handle.Name] = float64(incr) } +// WaitForFloat64Histo waits for a float histo metric to be recorded and +// verifies that the recorded metrics data matches the expected +// metricsDataWant. func (r *TestMetricsRecorder) WaitForFloat64Histo(ctx context.Context, metricsDataWant MetricsData) { got, err := r.floatHistoCh.Receive(ctx) if err != nil { @@ -192,6 +211,8 @@ func (r *TestMetricsRecorder) WaitForFloat64Histo(ctx context.Context, metricsDa } } +// RecordFloat64Histo sends the metrics data to the floatHistoCh channel +// and updates the internal data map with the recorded value. func (r *TestMetricsRecorder) RecordFloat64Histo(handle *estats.Float64HistoHandle, incr float64, labels ...string) { r.floatHistoCh.Send(MetricsData{ Handle: handle.Descriptor(), @@ -205,6 +226,9 @@ func (r *TestMetricsRecorder) RecordFloat64Histo(handle *estats.Float64HistoHand r.data[handle.Name] = incr } +// WaitForInt64Gauge waits for a int gauge metric to be recorded and +// verifies that the recorded metrics data matches the expected +// metricsDataWant. func (r *TestMetricsRecorder) WaitForInt64Gauge(ctx context.Context, metricsDataWant MetricsData) { got, err := r.intGaugeCh.Receive(ctx) if err != nil { @@ -216,6 +240,8 @@ func (r *TestMetricsRecorder) WaitForInt64Gauge(ctx context.Context, metricsData } } +// RecordInt64Gauge sends the metrics data to the intGaugeCh channel +// and updates the internal data map with the recorded value. func (r *TestMetricsRecorder) RecordInt64Gauge(handle *estats.Int64GaugeHandle, incr int64, labels ...string) { r.intGaugeCh.Send(MetricsData{ Handle: handle.Descriptor(), @@ -231,28 +257,37 @@ func (r *TestMetricsRecorder) RecordInt64Gauge(handle *estats.Int64GaugeHandle, // To implement a stats.Handler, which allows it to be set as a dial option: +// TagRPC is TestMetricsRecorder's implementation of TagRPC. func (r *TestMetricsRecorder) TagRPC(ctx context.Context, _ *stats.RPCTagInfo) context.Context { return ctx } +// HandleRPC is TestMetricsRecorder's implementation of HandleRPC. func (r *TestMetricsRecorder) HandleRPC(context.Context, stats.RPCStats) {} +// TagConn is TestMetricsRecorder's implementation of TagConn. func (r *TestMetricsRecorder) TagConn(ctx context.Context, _ *stats.ConnTagInfo) context.Context { return ctx } +// HandleConn is TestMetricsRecorder's implementation of HandleConn. func (r *TestMetricsRecorder) HandleConn(context.Context, stats.ConnStats) {} // NoopMetricsRecorder is a noop MetricsRecorder to be used in tests to prevent // nil panics. type NoopMetricsRecorder struct{} +// RecordInt64Count is a noop implementation of RecordInt64Count. func (r *NoopMetricsRecorder) RecordInt64Count(*estats.Int64CountHandle, int64, ...string) {} +// RecordFloat64Count is a noop implementation of RecordFloat64Count. func (r *NoopMetricsRecorder) RecordFloat64Count(*estats.Float64CountHandle, float64, ...string) {} +// RecordInt64Histo is a noop implementation of RecordInt64Histo. func (r *NoopMetricsRecorder) RecordInt64Histo(*estats.Int64HistoHandle, int64, ...string) {} +// RecordFloat64Histo is a noop implementation of RecordFloat64Histo. func (r *NoopMetricsRecorder) RecordFloat64Histo(*estats.Float64HistoHandle, float64, ...string) {} +// RecordInt64Gauge is a noop implementation of RecordInt64Gauge. func (r *NoopMetricsRecorder) RecordInt64Gauge(*estats.Int64GaugeHandle, int64, ...string) {} diff --git a/internal/transport/transport.go b/internal/transport/transport.go index fdd6fa86cc15..9a3bb3a63eae 100644 --- a/internal/transport/transport.go +++ b/internal/transport/transport.go @@ -547,6 +547,15 @@ func (s *Stream) write(m recvMsg) { s.buf.put(m) } +// ReadHeader reads data into the provided header slice from the stream. It +// first checks if there was an error during a previous read operation and +// returns it if present. It then requests a read operation for the length of +// the header. It continues to read from the stream until the entire header +// slice is filled or an error occurs. If an `io.EOF` error is encountered +// with partially read data, it is converted to `io.ErrUnexpectedEOF` to +// indicate an unexpected end of the stream. The method returns any error +// encountered during the read process or nil if the header was successfully +// read. func (s *Stream) ReadHeader(header []byte) (err error) { // Don't request a read if there was an error earlier if er := s.trReader.er; er != nil { diff --git a/mem/buffers.go b/mem/buffers.go index 4d66b2ccc2be..565ec0a13949 100644 --- a/mem/buffers.go +++ b/mem/buffers.go @@ -65,6 +65,9 @@ var ( refObjectPool = sync.Pool{New: func() any { return new(atomic.Int32) }} ) +// IsBelowBufferPoolingThreshold returns true if the given size is less than or +// equal to the threshold for buffer pooling. This is used to determine whether +// to pool buffers or allocate them directly. func IsBelowBufferPoolingThreshold(size int) bool { return size <= bufferPoolingThreshold } @@ -194,19 +197,19 @@ func (b *buffer) read(buf []byte) (int, Buffer) { return n, b } -// String returns a string representation of the buffer. May be used for -// debugging purposes. func (b *buffer) String() string { return fmt.Sprintf("mem.Buffer(%p, data: %p, length: %d)", b, b.ReadOnlyData(), len(b.ReadOnlyData())) } +// ReadUnsafe reads bytes from the given Buffer into the provided slice. +// It does not perform safety checks. func ReadUnsafe(dst []byte, buf Buffer) (int, Buffer) { return buf.read(dst) } // SplitUnsafe modifies the receiver to point to the first n bytes while it -// returns a new reference to the remaining bytes. The returned Buffer functions -// just like a normal reference acquired using Ref(). +// returns a new reference to the remaining bytes. The returned Buffer +// functions just like a normal reference acquired using Ref(). func SplitUnsafe(buf Buffer, n int) (left, right Buffer) { return buf.split(n) } @@ -232,12 +235,21 @@ func (e emptyBuffer) read([]byte) (int, Buffer) { return 0, e } +// SliceBuffer is a Buffer implementation that wraps a byte slice. It provides +// methods for reading, splitting, and managing the byte slice. type SliceBuffer []byte +// ReadOnlyData returns the byte slice. func (s SliceBuffer) ReadOnlyData() []byte { return s } -func (s SliceBuffer) Ref() {} -func (s SliceBuffer) Free() {} -func (s SliceBuffer) Len() int { return len(s) } + +// Ref is a noop implementation of Ref. +func (s SliceBuffer) Ref() {} + +// Free is a noop implementation of Free. +func (s SliceBuffer) Free() {} + +// Len is a noop implementation of Len. +func (s SliceBuffer) Len() int { return len(s) } func (s SliceBuffer) split(n int) (left, right Buffer) { return s[:n], s[n:] diff --git a/rpc_util.go b/rpc_util.go index 2d96f1405e8d..aba1ae3e6784 100644 --- a/rpc_util.go +++ b/rpc_util.go @@ -791,9 +791,8 @@ func checkRecvPayload(pf payloadFormat, recvCompress string, haveCompressor bool if !haveCompressor { if isServer { return status.Newf(codes.Unimplemented, "grpc: Decompressor is not installed for grpc-encoding %q", recvCompress) - } else { - return status.Newf(codes.Internal, "grpc: Decompressor is not installed for grpc-encoding %q", recvCompress) } + return status.Newf(codes.Internal, "grpc: Decompressor is not installed for grpc-encoding %q", recvCompress) } default: return status.Newf(codes.Internal, "grpc: received unexpected payload format %d", pf) diff --git a/scripts/revive.toml b/scripts/revive.toml index ea43fcdf34db..d6565df07c2e 100644 --- a/scripts/revive.toml +++ b/scripts/revive.toml @@ -7,9 +7,13 @@ [rule.error-return] [rule.error-strings] [rule.error-naming] +[rule.exported] [rule.increment-decrement] +[rule.indent-error-flow] +[rule.package-comments] [rule.range] [rule.receiver-naming] +[rule.redefines-builtin-id] [rule.superfluous-else] [rule.time-naming] [rule.var-naming] @@ -25,11 +29,4 @@ Disabled = true [rule.import-shadowing] Disabled = true -[rule.exported] - Disabled = true # TODO: Enable after existing issues are fixed -[rule.redefines-builtin-id] - Disabled = true # TODO: Enable after existing issues are fixed -[rule.package-comments] - Disabled = true # TODO: Enable after existing issues are fixed -[rule.indent-error-flow] - Disabled = true # TODO: Enable after existing issues are fixed + diff --git a/security/advancedtls/advancedtls.go b/security/advancedtls/advancedtls.go index cda5dc8ac4f9..ddd67aa2dec9 100644 --- a/security/advancedtls/advancedtls.go +++ b/security/advancedtls/advancedtls.go @@ -41,6 +41,9 @@ import ( credinternal "google.golang.org/grpc/internal/credentials" ) +// CertificateChains represents a slice of certificate chains, each consisting +// of a sequence of certificates. Each chain represents a path from a leaf +// certificate up to a root certificate in the certificate hierarchy. type CertificateChains [][]*x509.Certificate // HandshakeVerificationInfo contains information about a handshake needed for