From 0ecc2b422f280cddcfaae2ff63b81aec2f04cb69 Mon Sep 17 00:00:00 2001 From: "jesse.tang" <1430482733@qq.com> Date: Tue, 27 Sep 2022 23:14:29 +0800 Subject: [PATCH] style: modify declaring empty slices (#2378) * fix: modify declaring empty slices declare an empty slice to var s []int replace s :=[]int{}, https://github.com/golang/go/wiki/CodeReviewComments#declaring-empty-slices * fix lint --- contrib/registry/eureka/register.go | 7 ++----- middleware/tracing/span.go | 10 ++++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/contrib/registry/eureka/register.go b/contrib/registry/eureka/register.go index 62ee81cfc..9588df641 100644 --- a/contrib/registry/eureka/register.go +++ b/contrib/registry/eureka/register.go @@ -92,12 +92,9 @@ func (r *Registry) Watch(ctx context.Context, serviceName string) (registry.Watc } func (r *Registry) Endpoints(service *registry.ServiceInstance) []Endpoint { - var ( - res = []Endpoint{} - start int - ) + res := make([]Endpoint, 0, len(service.Endpoints)) for _, ep := range service.Endpoints { - start = strings.Index(ep, "//") + start := strings.Index(ep, "//") end := strings.LastIndex(ep, ":") appID := strings.ToUpper(service.Name) ip := ep[start+2 : end] diff --git a/middleware/tracing/span.go b/middleware/tracing/span.go index 7edb914eb..a0a9d462d 100644 --- a/middleware/tracing/span.go +++ b/middleware/tracing/span.go @@ -57,10 +57,12 @@ func setClientSpan(ctx context.Context, span trace.Span, m interface{}) { } func setServerSpan(ctx context.Context, span trace.Span, m interface{}) { - attrs := []attribute.KeyValue{} - var remote string - var operation string - var rpcKind string + var ( + attrs []attribute.KeyValue + remote string + operation string + rpcKind string + ) tr, ok := transport.FromServerContext(ctx) if ok { operation = tr.Operation()