From fb26eb6360f085e06afbc8f9c449d60e0cda4ecf Mon Sep 17 00:00:00 2001 From: thinkerou Date: Wed, 18 Oct 2017 10:12:36 +0800 Subject: [PATCH] not use brackets if only one var --- backoff.go | 14 +++++----- benchmark/server/main.go | 4 +-- benchmark/worker/benchmark_client.go | 4 +-- codec.go | 18 ++++++------- credentials/credentials.go | 14 ++++------ .../mock_routeguide/rg_mock_test.go | 10 +++---- interop/test_utils.go | 10 +++---- resolver/dns/dns_resolver.go | 4 +-- resolver/dns/dns_resolver_test.go | 26 ++++++++----------- resolver/dns/go17_test.go | 4 +-- resolver/dns/go18_test.go | 4 +-- server.go | 8 +++--- transport/bdp_estimator.go | 9 +++---- 13 files changed, 49 insertions(+), 80 deletions(-) diff --git a/backoff.go b/backoff.go index 090fbe87c522..c40facce5103 100644 --- a/backoff.go +++ b/backoff.go @@ -25,14 +25,12 @@ import ( // DefaultBackoffConfig uses values specified for backoff in // https://github.com/grpc/grpc/blob/master/doc/connection-backoff.md. -var ( - DefaultBackoffConfig = BackoffConfig{ - MaxDelay: 120 * time.Second, - baseDelay: 1.0 * time.Second, - factor: 1.6, - jitter: 0.2, - } -) +var DefaultBackoffConfig = BackoffConfig{ + MaxDelay: 120 * time.Second, + baseDelay: 1.0 * time.Second, + factor: 1.6, + jitter: 0.2, +} // backoffStrategy defines the methodology for backing off after a grpc // connection failure. diff --git a/benchmark/server/main.go b/benchmark/server/main.go index dcce130e478d..ac59ff771d72 100644 --- a/benchmark/server/main.go +++ b/benchmark/server/main.go @@ -30,9 +30,7 @@ import ( "google.golang.org/grpc/grpclog" ) -var ( - duration = flag.Int("duration", math.MaxInt32, "The duration in seconds to run the benchmark server") -) +var duration = flag.Int("duration", math.MaxInt32, "The duration in seconds to run the benchmark server") func main() { flag.Parse() diff --git a/benchmark/worker/benchmark_client.go b/benchmark/worker/benchmark_client.go index 9db1d8504a80..072ceee4ed01 100644 --- a/benchmark/worker/benchmark_client.go +++ b/benchmark/worker/benchmark_client.go @@ -37,9 +37,7 @@ import ( "google.golang.org/grpc/testdata" ) -var ( - caFile = flag.String("ca_file", "", "The file containing the CA root cert file") -) +var caFile = flag.String("ca_file", "", "The file containing the CA root cert file") type lockingHistogram struct { mu sync.Mutex diff --git a/codec.go b/codec.go index 905b048e2ac5..b452a4ae8da4 100644 --- a/codec.go +++ b/codec.go @@ -92,13 +92,11 @@ func (protoCodec) String() string { return "proto" } -var ( - protoBufferPool = &sync.Pool{ - New: func() interface{} { - return &cachedProtoBuffer{ - Buffer: proto.Buffer{}, - lastMarshaledSize: 16, - } - }, - } -) +var protoBufferPool = &sync.Pool{ + New: func() interface{} { + return &cachedProtoBuffer{ + Buffer: proto.Buffer{}, + lastMarshaledSize: 16, + } + }, +} diff --git a/credentials/credentials.go b/credentials/credentials.go index 2475fe832205..c6575b5c78e7 100644 --- a/credentials/credentials.go +++ b/credentials/credentials.go @@ -34,10 +34,8 @@ import ( "golang.org/x/net/context" ) -var ( - // alpnProtoStr are the specified application level protocols for gRPC. - alpnProtoStr = []string{"h2"} -) +// alpnProtoStr are the specified application level protocols for gRPC. +var alpnProtoStr = []string{"h2"} // PerRPCCredentials defines the common interface for the credentials which need to // attach security information to every RPC (e.g., oauth2). @@ -74,11 +72,9 @@ type AuthInfo interface { AuthType() string } -var ( - // ErrConnDispatched indicates that rawConn has been dispatched out of gRPC - // and the caller should not close rawConn. - ErrConnDispatched = errors.New("credentials: rawConn is dispatched out of gRPC") -) +// ErrConnDispatched indicates that rawConn has been dispatched out of gRPC +// and the caller should not close rawConn. +var ErrConnDispatched = errors.New("credentials: rawConn is dispatched out of gRPC") // TransportCredentials defines the common interface for all the live gRPC wire // protocols and supported transport security protocols (e.g., TLS, SSL). diff --git a/examples/route_guide/mock_routeguide/rg_mock_test.go b/examples/route_guide/mock_routeguide/rg_mock_test.go index 8c6d63c72e7c..d084bd6ae1e5 100644 --- a/examples/route_guide/mock_routeguide/rg_mock_test.go +++ b/examples/route_guide/mock_routeguide/rg_mock_test.go @@ -29,12 +29,10 @@ import ( rgpb "google.golang.org/grpc/examples/route_guide/routeguide" ) -var ( - msg = &rgpb.RouteNote{ - Location: &rgpb.Point{Latitude: 17, Longitude: 29}, - Message: "Taxi-cab", - } -) +var msg = &rgpb.RouteNote{ + Location: &rgpb.Point{Latitude: 17, Longitude: 29}, + Message: "Taxi-cab", +} func TestRouteChat(t *testing.T) { ctrl := gomock.NewController(t) diff --git a/interop/test_utils.go b/interop/test_utils.go index 119c87218df8..c609b921185c 100644 --- a/interop/test_utils.go +++ b/interop/test_utils.go @@ -394,12 +394,10 @@ func DoPerRPCCreds(tc testpb.TestServiceClient, serviceAccountKeyFile, oauthScop } } -var ( - testMetadata = metadata.MD{ - "key1": []string{"value1"}, - "key2": []string{"value2"}, - } -) +var testMetadata = metadata.MD{ + "key1": []string{"value1"}, + "key2": []string{"value2"}, +} // DoCancelAfterBegin cancels the RPC after metadata has been sent but before payloads are sent. func DoCancelAfterBegin(tc testpb.TestServiceClient, args ...grpc.CallOption) { diff --git a/resolver/dns/dns_resolver.go b/resolver/dns/dns_resolver.go index f31bbb60fd58..a543a709a623 100644 --- a/resolver/dns/dns_resolver.go +++ b/resolver/dns/dns_resolver.go @@ -50,9 +50,7 @@ const ( txtAttribute = "grpc_config=" ) -var ( - errMissingAddr = errors.New("missing address") -) +var errMissingAddr = errors.New("missing address") // NewBuilder creates a dnsBuilder which is used to factory DNS resolvers. func NewBuilder() resolver.Builder { diff --git a/resolver/dns/dns_resolver_test.go b/resolver/dns/dns_resolver_test.go index 590791168230..41a9ecb9144a 100644 --- a/resolver/dns/dns_resolver_test.go +++ b/resolver/dns/dns_resolver_test.go @@ -150,9 +150,8 @@ func div(b []byte) []string { // resolver functionality, with scfs as the input and scs used for validation of // the output. For scfs[3], it corresponds to empty service config, since there // isn't a matched choice. -var ( - scfs = []string{ - `[ +var scfs = []string{ + `[ { "clientLanguage": [ "CPP", @@ -242,7 +241,7 @@ var ( } } ]`, - `[ + `[ { "clientLanguage": [ "CPP", @@ -335,7 +334,7 @@ var ( } } ]`, - `[ + `[ { "clientLanguage": [ "CPP", @@ -434,7 +433,7 @@ var ( } } ]`, - `[ + `[ { "clientLanguage": [ "CPP", @@ -489,13 +488,11 @@ var ( } } ]`, - } -) +} // scs contains an array of service config string in JSON format. -var ( - scs = []string{ - `{ +var scs = []string{ + `{ "methodConfig": [ { "name": [ @@ -508,7 +505,7 @@ var ( } ] }`, - `{ + `{ "methodConfig": [ { "name": [ @@ -524,7 +521,7 @@ var ( } ] }`, - `{ + `{ "loadBalancingPolicy": "round_robin", "methodConfig": [ { @@ -546,8 +543,7 @@ var ( } ] }`, - } -) +} // scLookupTbl is a set, which contains targets that have service config. Target // not in this set should not have service config. diff --git a/resolver/dns/go17_test.go b/resolver/dns/go17_test.go index 07fdcb03f88a..21eaa8885c7a 100644 --- a/resolver/dns/go17_test.go +++ b/resolver/dns/go17_test.go @@ -27,9 +27,7 @@ import ( "golang.org/x/net/context" ) -var ( - errForInvalidTarget = fmt.Errorf("invalid target address [2001:db8:a0b:12f0::1, error info: missing ']' in address [2001:db8:a0b:12f0::1:443") -) +var errForInvalidTarget = fmt.Errorf("invalid target address [2001:db8:a0b:12f0::1, error info: missing ']' in address [2001:db8:a0b:12f0::1:443") func replaceNetFunc() func() { oldLookupHost := lookupHost diff --git a/resolver/dns/go18_test.go b/resolver/dns/go18_test.go index 8e016709c1d7..b0149c867709 100644 --- a/resolver/dns/go18_test.go +++ b/resolver/dns/go18_test.go @@ -26,9 +26,7 @@ import ( "net" ) -var ( - errForInvalidTarget = fmt.Errorf("invalid target address [2001:db8:a0b:12f0::1, error info: address [2001:db8:a0b:12f0::1:443: missing ']' in address") -) +var errForInvalidTarget = fmt.Errorf("invalid target address [2001:db8:a0b:12f0::1, error info: address [2001:db8:a0b:12f0::1:443: missing ']' in address") func replaceNetFunc() func() { oldLookupHost := lookupHost diff --git a/server.go b/server.go index 7c882dbe6d77..5537fdf2537d 100644 --- a/server.go +++ b/server.go @@ -418,11 +418,9 @@ func (s *Server) GetServiceInfo() map[string]ServiceInfo { return ret } -var ( - // ErrServerStopped indicates that the operation is now illegal because of - // the server being stopped. - ErrServerStopped = errors.New("grpc: the server has been stopped") -) +// ErrServerStopped indicates that the operation is now illegal because of +// the server being stopped. +var ErrServerStopped = errors.New("grpc: the server has been stopped") func (s *Server) useTransportAuthenticator(rawConn net.Conn) (net.Conn, credentials.AuthInfo, error) { if s.opts.creds == nil { diff --git a/transport/bdp_estimator.go b/transport/bdp_estimator.go index 8dd2ed42792f..63cd2627c87a 100644 --- a/transport/bdp_estimator.go +++ b/transport/bdp_estimator.go @@ -41,12 +41,9 @@ const ( gamma = 2 ) -var ( - // Adding arbitrary data to ping so that its ack can be - // identified. - // Easter-egg: what does the ping message say? - bdpPing = &ping{data: [8]byte{2, 4, 16, 16, 9, 14, 7, 7}} -) +// Adding arbitrary data to ping so that its ack can be identified. +// Easter-egg: what does the ping message say? +var bdpPing = &ping{data: [8]byte{2, 4, 16, 16, 9, 14, 7, 7}} type bdpEstimator struct { // sentAt is the time when the ping was sent.