From ac90a026b68143ce3fc529496551e33284ddfe64 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 27 Jul 2016 10:49:12 -0400 Subject: [PATCH] *: go vet --- .travis.yml | 1 + examples/route_guide/client/client.go | 11 +++++++---- examples/route_guide/server/server.go | 2 +- reflection/serverreflection.go | 2 +- rpc_util_test.go | 4 ++-- server.go | 6 +++--- server_test.go | 4 ++-- 7 files changed, 17 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 28e80cde7..0eddb1cbb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,4 +19,5 @@ script: - '! gofmt -s -d -l . 2>&1 | read' - '! goimports -l . | read' - '! golint ./... | grep -vE "(_string|\.pb)\.go:"' + - '! go tool vet -all . 2>&1 | grep -vE "constant [0-9]+ not a string in call to Errorf"' - make test testrace diff --git a/examples/route_guide/client/client.go b/examples/route_guide/client/client.go index 02c049097..fff6398d4 100644 --- a/examples/route_guide/client/client.go +++ b/examples/route_guide/client/client.go @@ -153,7 +153,7 @@ func runRouteChat(client pb.RouteGuideClient) { func randomPoint(r *rand.Rand) *pb.Point { lat := (r.Int31n(180) - 90) * 1e7 long := (r.Int31n(360) - 180) * 1e7 - return &pb.Point{lat, long} + return &pb.Point{Latitude: lat, Longitude: long} } func main() { @@ -186,13 +186,16 @@ func main() { client := pb.NewRouteGuideClient(conn) // Looking for a valid feature - printFeature(client, &pb.Point{409146138, -746188906}) + printFeature(client, &pb.Point{Latitude: 409146138, Longitude: -746188906}) // Feature missing. - printFeature(client, &pb.Point{0, 0}) + printFeature(client, &pb.Point{Latitude: 0, Longitude: 0}) // Looking for features between 40, -75 and 42, -73. - printFeatures(client, &pb.Rectangle{&pb.Point{Latitude: 400000000, Longitude: -750000000}, &pb.Point{Latitude: 420000000, Longitude: -730000000}}) + printFeatures(client, &pb.Rectangle{ + Lo: &pb.Point{Latitude: 400000000, Longitude: -750000000}, + Hi: &pb.Point{Latitude: 420000000, Longitude: -730000000}, + }) // RecordRoute runRecordRoute(client) diff --git a/examples/route_guide/server/server.go b/examples/route_guide/server/server.go index c8be49709..5932722bf 100644 --- a/examples/route_guide/server/server.go +++ b/examples/route_guide/server/server.go @@ -79,7 +79,7 @@ func (s *routeGuideServer) GetFeature(ctx context.Context, point *pb.Point) (*pb } } // No feature was found, return an unnamed feature - return &pb.Feature{"", point}, nil + return &pb.Feature{Location: point}, nil } // ListFeatures lists all features contained within the given bounding Rectangle. diff --git a/reflection/serverreflection.go b/reflection/serverreflection.go index c3327ac5d..686090aa5 100644 --- a/reflection/serverreflection.go +++ b/reflection/serverreflection.go @@ -70,7 +70,7 @@ import ( type serverReflectionServer struct { s *grpc.Server // TODO add more cache if necessary - serviceInfo map[string]*grpc.ServiceInfo // cache for s.GetServiceInfo() + serviceInfo map[string]grpc.ServiceInfo // cache for s.GetServiceInfo() } // Register registers the server reflection service on the given gRPC server. diff --git a/rpc_util_test.go b/rpc_util_test.go index 5a802d651..830546c62 100644 --- a/rpc_util_test.go +++ b/rpc_util_test.go @@ -184,8 +184,8 @@ func TestContextErr(t *testing.T) { func TestErrorsWithSameParameters(t *testing.T) { const description = "some description" - e1 := Errorf(codes.AlreadyExists, description) - e2 := Errorf(codes.AlreadyExists, description) + e1 := Errorf(codes.AlreadyExists, description).(*rpcError) + e2 := Errorf(codes.AlreadyExists, description).(*rpcError) if e1 == e2 { t.Fatalf("Error interfaces should not be considered equal - e1: %p - %v e2: %p - %v", e1, e1, e2, e2) } diff --git a/server.go b/server.go index 1a250c796..587daae2a 100644 --- a/server.go +++ b/server.go @@ -269,8 +269,8 @@ type ServiceInfo struct { // GetServiceInfo returns a map from service names to ServiceInfo. // Service names include the package names, in the form of .. -func (s *Server) GetServiceInfo() map[string]*ServiceInfo { - ret := make(map[string]*ServiceInfo) +func (s *Server) GetServiceInfo() map[string]ServiceInfo { + ret := make(map[string]ServiceInfo) for n, srv := range s.m { methods := make([]MethodInfo, 0, len(srv.md)+len(srv.sd)) for m := range srv.md { @@ -288,7 +288,7 @@ func (s *Server) GetServiceInfo() map[string]*ServiceInfo { }) } - ret[n] = &ServiceInfo{ + ret[n] = ServiceInfo{ Methods: methods, Metadata: srv.mdata, } diff --git a/server_test.go b/server_test.go index 6ea4dac31..23838806d 100644 --- a/server_test.go +++ b/server_test.go @@ -90,7 +90,7 @@ func TestGetServiceInfo(t *testing.T) { server.RegisterService(&testSd, &testServer{}) info := server.GetServiceInfo() - want := map[string]*ServiceInfo{ + want := map[string]ServiceInfo{ "grpc.testing.EmptyService": { Methods: []MethodInfo{ { @@ -108,6 +108,6 @@ func TestGetServiceInfo(t *testing.T) { } if !reflect.DeepEqual(info, want) { - t.Errorf("GetServiceInfo() = %q, want %q", info, want) + t.Errorf("GetServiceInfo() = %+v, want %+v", info, want) } }