Skip to content

Commit

Permalink
.*: fix revive lints redefines-builtin-id (#7552)
Browse files Browse the repository at this point in the history
* Fix revive identified linter issues: redefines-builtin-id
---------

Co-authored-by: Vissa Janardhan Krishna Sai <vissajanardhan@google.com>
Co-authored-by: Purnesh Dixit <purnesh.dixit92@gmail.com>
Co-authored-by: Arvind Bright <arvind.bright100@gmail.com>
  • Loading branch information
4 people committed Sep 7, 2024
1 parent 5666049 commit 3ffb98b
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 34 deletions.
4 changes: 2 additions & 2 deletions balancer_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ func (acbw *acBalancerWrapper) GetOrBuildProducer(pb balancer.ProducerBuilder) (
pData := acbw.producers[pb]
if pData == nil {
// Not found; create a new one and add it to the producers map.
p, close := pb.Build(acbw)
pData = &refCountedProducer{producer: p, close: close}
p, closeFn := pb.Build(acbw)
pData = &refCountedProducer{producer: p, close: closeFn}
acbw.producers[pb] = pData
}
// Account for this new reference.
Expand Down
4 changes: 2 additions & 2 deletions internal/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ func (s *Status) WithDetails(details ...protoadapt.MessageV1) (*Status, error) {
// s.Code() != OK implies that s.Proto() != nil.
p := s.Proto()
for _, detail := range details {
any, err := anypb.New(protoadapt.MessageV2Of(detail))
m, err := anypb.New(protoadapt.MessageV2Of(detail))
if err != nil {
return nil, err
}
p.Details = append(p.Details, any)
p.Details = append(p.Details, m)
}
return &Status{s: p}, nil
}
Expand Down
4 changes: 2 additions & 2 deletions internal/xds/rbac/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ func buildLogger(loggerConfig *v3rbacpb.RBAC_AuditLoggingOptions_AuditLoggerConf
}

func getCustomConfig(config *anypb.Any) (json.RawMessage, string, error) {
any, err := config.UnmarshalNew()
c, err := config.UnmarshalNew()
if err != nil {
return nil, "", err
}
switch m := any.(type) {
switch m := c.(type) {
case *v1xdsudpatypepb.TypedStruct:
return convertCustomConfig(m.TypeUrl, m.Value)
case *v3xdsxdstypepb.TypedStruct:
Expand Down
4 changes: 2 additions & 2 deletions orca/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type OOBListenerOptions struct {
// returned stop function must be called when no longer needed. Do not
// register a single OOBListener more than once per SubConn.
func RegisterOOBListener(sc balancer.SubConn, l OOBListener, opts OOBListenerOptions) (stop func()) {
pr, close := sc.GetOrBuildProducer(producerBuilderSingleton)
pr, closeFn := sc.GetOrBuildProducer(producerBuilderSingleton)
p := pr.(*producer)

p.registerListener(l, opts.ReportInterval)
Expand All @@ -84,7 +84,7 @@ func RegisterOOBListener(sc balancer.SubConn, l OOBListener, opts OOBListenerOpt
// subsequent calls.
return grpcsync.OnceFunc(func() {
p.unregisterListener(l, opts.ReportInterval)
close()
closeFn()
})
}

Expand Down
4 changes: 2 additions & 2 deletions stats/opentelemetry/server_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (h *serverStatsHandler) unaryInterceptor(ctx context.Context, req any, _ *g
}
ctx = grpc.NewContextWithServerTransportStream(ctx, alts)

any, err := handler(ctx, req)
res, err := handler(ctx, req)
if err != nil { // maybe trailers-only if headers haven't already been sent
if !alts.attachedLabels.Swap(true) {
alts.SetTrailer(alts.metadataExchangeLabels)
Expand All @@ -115,7 +115,7 @@ func (h *serverStatsHandler) unaryInterceptor(ctx context.Context, req any, _ *g
}
}

return any, err
return res, err
}

// attachLabelsStream embeds a grpc.ServerStream, and intercepts the
Expand Down
4 changes: 2 additions & 2 deletions status/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,11 @@ func str(s *Status) string {

// mustMarshalAny converts a protobuf message to an any.
func mustMarshalAny(msg proto.Message) *anypb.Any {
any, err := anypb.New(msg)
m, err := anypb.New(msg)
if err != nil {
panic(fmt.Sprintf("anypb.New(%+v) failed: %v", msg, err))
}
return any
return m
}

func (s) TestFromContextError(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions xds/internal/clusterspecifier/rls/rls.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ func (rls) ParseClusterSpecifierConfig(cfg proto.Message) (clusterspecifier.Bala
if cfg == nil {
return nil, fmt.Errorf("rls_csp: nil configuration message provided")
}
any, ok := cfg.(*anypb.Any)
m, ok := cfg.(*anypb.Any)
if !ok {
return nil, fmt.Errorf("rls_csp: error parsing config %v: unknown type %T", cfg, cfg)
}
rlcs := new(rlspb.RouteLookupClusterSpecifier)

if err := any.UnmarshalTo(rlcs); err != nil {
if err := m.UnmarshalTo(rlcs); err != nil {
return nil, fmt.Errorf("rls_csp: error parsing config %v: %v", cfg, err)
}
rlcJSON, err := protojson.Marshal(rlcs.GetRouteLookupConfig())
Expand Down
4 changes: 2 additions & 2 deletions xds/internal/httpfilter/fault/fault.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ func parseConfig(cfg proto.Message) (httpfilter.FilterConfig, error) {
if cfg == nil {
return nil, fmt.Errorf("fault: nil configuration message provided")
}
any, ok := cfg.(*anypb.Any)
m, ok := cfg.(*anypb.Any)
if !ok {
return nil, fmt.Errorf("fault: error parsing config %v: unknown type %T", cfg, cfg)
}
msg := new(fpb.HTTPFault)
if err := any.UnmarshalTo(msg); err != nil {
if err := m.UnmarshalTo(msg); err != nil {
return nil, fmt.Errorf("fault: error parsing config %v: %v", cfg, err)
}
return config{config: msg}, nil
Expand Down
8 changes: 4 additions & 4 deletions xds/internal/httpfilter/rbac/rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ func (builder) ParseFilterConfig(cfg proto.Message) (httpfilter.FilterConfig, er
if cfg == nil {
return nil, fmt.Errorf("rbac: nil configuration message provided")
}
any, ok := cfg.(*anypb.Any)
m, ok := cfg.(*anypb.Any)
if !ok {
return nil, fmt.Errorf("rbac: error parsing config %v: unknown type %T", cfg, cfg)
}
msg := new(rpb.RBAC)
if err := any.UnmarshalTo(msg); err != nil {
if err := m.UnmarshalTo(msg); err != nil {
return nil, fmt.Errorf("rbac: error parsing config %v: %v", cfg, err)
}
return parseConfig(msg)
Expand All @@ -156,12 +156,12 @@ func (builder) ParseFilterConfigOverride(override proto.Message) (httpfilter.Fil
if override == nil {
return nil, fmt.Errorf("rbac: nil configuration message provided")
}
any, ok := override.(*anypb.Any)
m, ok := override.(*anypb.Any)
if !ok {
return nil, fmt.Errorf("rbac: error parsing override config %v: unknown type %T", override, override)
}
msg := new(rpb.RBACPerRoute)
if err := any.UnmarshalTo(msg); err != nil {
if err := m.UnmarshalTo(msg); err != nil {
return nil, fmt.Errorf("rbac: error parsing override config %v: %v", override, err)
}
return parseConfig(msg.Rbac)
Expand Down
4 changes: 2 additions & 2 deletions xds/internal/httpfilter/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ func (builder) ParseFilterConfig(cfg proto.Message) (httpfilter.FilterConfig, er
if cfg == nil {
return nil, fmt.Errorf("router: nil configuration message provided")
}
any, ok := cfg.(*anypb.Any)
m, ok := cfg.(*anypb.Any)
if !ok {
return nil, fmt.Errorf("router: error parsing config %v: unknown type %T", cfg, cfg)
}
msg := new(pb.Router)
if err := any.UnmarshalTo(msg); err != nil {
if err := m.UnmarshalTo(msg); err != nil {
return nil, fmt.Errorf("router: error parsing config %v: %v", cfg, err)
}
return config{}, nil
Expand Down
4 changes: 2 additions & 2 deletions xds/internal/resolver/xds_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ func (b *xdsResolverBuilder) Build(target resolver.Target, cc resolver.ClientCon
if b.newXDSClient != nil {
newXDSClient = b.newXDSClient
}
client, close, err := newXDSClient(target.String())
client, closeFn, err := newXDSClient(target.String())
if err != nil {
return nil, fmt.Errorf("xds: failed to create xds-client: %v", err)
}
r.xdsClient = client
r.xdsClientClose = close
r.xdsClientClose = closeFn

// Determine the listener resource name and start a watcher for it.
template, err := r.sanityChecksOnBootstrapConfig(target, opts, r.xdsClient)
Expand Down
4 changes: 2 additions & 2 deletions xds/internal/xdsclient/loadreport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ func (s) TestLRSClient(t *testing.T) {
t.Fatalf("Failed to create server config for testing: %v", err)
}
bc := e2e.DefaultBootstrapContents(t, nodeID, fs1.Address)
xdsC, close, err := NewForTesting(OptionsForTesting{
xdsC, closeFn, err := NewForTesting(OptionsForTesting{
Name: t.Name(),
Contents: bc,
WatchExpiryTimeout: defaultTestWatchExpiryTimeout,
})
if err != nil {
t.Fatalf("Failed to create an xDS client: %v", err)
}
defer close()
defer closeFn()

// Report to the same address should not create new ClientConn.
store1, lrsCancel1 := xdsC.ReportLoad(serverCfg1)
Expand Down
8 changes: 4 additions & 4 deletions xds/internal/xdsclient/xdsresource/filter_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,12 +536,12 @@ func (fcm *FilterChainManager) filterChainFromProto(fc *v3listenerpb.FilterChain
if name := ts.GetName(); name != transportSocketName {
return nil, fmt.Errorf("transport_socket field has unexpected name: %s", name)
}
any := ts.GetTypedConfig()
if any == nil || any.TypeUrl != version.V3DownstreamTLSContextURL {
return nil, fmt.Errorf("transport_socket field has unexpected typeURL: %s", any.TypeUrl)
tc := ts.GetTypedConfig()
if tc == nil || tc.TypeUrl != version.V3DownstreamTLSContextURL {
return nil, fmt.Errorf("transport_socket field has unexpected typeURL: %s", tc.TypeUrl)
}
downstreamCtx := &v3tlspb.DownstreamTlsContext{}
if err := proto.Unmarshal(any.GetValue(), downstreamCtx); err != nil {
if err := proto.Unmarshal(tc.GetValue(), downstreamCtx); err != nil {
return nil, fmt.Errorf("failed to unmarshal DownstreamTlsContext in LDS response: %v", err)
}
if downstreamCtx.GetRequireSni().GetValue() {
Expand Down
8 changes: 4 additions & 4 deletions xds/internal/xdsclient/xdsresource/unmarshal_cds.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,12 @@ func securityConfigFromCluster(cluster *v3clusterpb.Cluster) (*SecurityConfig, e
if name := ts.GetName(); name != transportSocketName {
return nil, fmt.Errorf("transport_socket field has unexpected name: %s", name)
}
any := ts.GetTypedConfig()
if any == nil || any.TypeUrl != version.V3UpstreamTLSContextURL {
return nil, fmt.Errorf("transport_socket field has unexpected typeURL: %s", any.TypeUrl)
tc := ts.GetTypedConfig()
if tc == nil || tc.TypeUrl != version.V3UpstreamTLSContextURL {
return nil, fmt.Errorf("transport_socket field has unexpected typeURL: %s", tc.TypeUrl)
}
upstreamCtx := &v3tlspb.UpstreamTlsContext{}
if err := proto.Unmarshal(any.GetValue(), upstreamCtx); err != nil {
if err := proto.Unmarshal(tc.GetValue(), upstreamCtx); err != nil {
return nil, fmt.Errorf("failed to unmarshal UpstreamTlsContext in CDS response: %v", err)
}
// The following fields from `UpstreamTlsContext` are ignored:
Expand Down

0 comments on commit 3ffb98b

Please sign in to comment.