*: go vet

This commit is contained in:
Tamir Duberstein
2016-07-27 10:49:12 -04:00
parent 220b464e81
commit ac90a026b6
7 changed files with 17 additions and 13 deletions

View File

@ -19,4 +19,5 @@ script:
- '! gofmt -s -d -l . 2>&1 | read' - '! gofmt -s -d -l . 2>&1 | read'
- '! goimports -l . | read' - '! goimports -l . | read'
- '! golint ./... | grep -vE "(_string|\.pb)\.go:"' - '! 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 - make test testrace

View File

@ -153,7 +153,7 @@ func runRouteChat(client pb.RouteGuideClient) {
func randomPoint(r *rand.Rand) *pb.Point { func randomPoint(r *rand.Rand) *pb.Point {
lat := (r.Int31n(180) - 90) * 1e7 lat := (r.Int31n(180) - 90) * 1e7
long := (r.Int31n(360) - 180) * 1e7 long := (r.Int31n(360) - 180) * 1e7
return &pb.Point{lat, long} return &pb.Point{Latitude: lat, Longitude: long}
} }
func main() { func main() {
@ -186,13 +186,16 @@ func main() {
client := pb.NewRouteGuideClient(conn) client := pb.NewRouteGuideClient(conn)
// Looking for a valid feature // Looking for a valid feature
printFeature(client, &pb.Point{409146138, -746188906}) printFeature(client, &pb.Point{Latitude: 409146138, Longitude: -746188906})
// Feature missing. // 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. // 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 // RecordRoute
runRecordRoute(client) runRecordRoute(client)

View File

@ -79,7 +79,7 @@ func (s *routeGuideServer) GetFeature(ctx context.Context, point *pb.Point) (*pb
} }
} }
// No feature was found, return an unnamed feature // 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. // ListFeatures lists all features contained within the given bounding Rectangle.

View File

@ -70,7 +70,7 @@ import (
type serverReflectionServer struct { type serverReflectionServer struct {
s *grpc.Server s *grpc.Server
// TODO add more cache if necessary // 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. // Register registers the server reflection service on the given gRPC server.

View File

@ -184,8 +184,8 @@ func TestContextErr(t *testing.T) {
func TestErrorsWithSameParameters(t *testing.T) { func TestErrorsWithSameParameters(t *testing.T) {
const description = "some description" const description = "some description"
e1 := Errorf(codes.AlreadyExists, description) e1 := Errorf(codes.AlreadyExists, description).(*rpcError)
e2 := Errorf(codes.AlreadyExists, description) e2 := Errorf(codes.AlreadyExists, description).(*rpcError)
if e1 == e2 { if e1 == e2 {
t.Fatalf("Error interfaces should not be considered equal - e1: %p - %v e2: %p - %v", e1, e1, e2, e2) t.Fatalf("Error interfaces should not be considered equal - e1: %p - %v e2: %p - %v", e1, e1, e2, e2)
} }

View File

@ -269,8 +269,8 @@ type ServiceInfo struct {
// GetServiceInfo returns a map from service names to ServiceInfo. // GetServiceInfo returns a map from service names to ServiceInfo.
// Service names include the package names, in the form of <package>.<service>. // Service names include the package names, in the form of <package>.<service>.
func (s *Server) GetServiceInfo() map[string]*ServiceInfo { func (s *Server) GetServiceInfo() map[string]ServiceInfo {
ret := make(map[string]*ServiceInfo) ret := make(map[string]ServiceInfo)
for n, srv := range s.m { for n, srv := range s.m {
methods := make([]MethodInfo, 0, len(srv.md)+len(srv.sd)) methods := make([]MethodInfo, 0, len(srv.md)+len(srv.sd))
for m := range srv.md { for m := range srv.md {
@ -288,7 +288,7 @@ func (s *Server) GetServiceInfo() map[string]*ServiceInfo {
}) })
} }
ret[n] = &ServiceInfo{ ret[n] = ServiceInfo{
Methods: methods, Methods: methods,
Metadata: srv.mdata, Metadata: srv.mdata,
} }

View File

@ -90,7 +90,7 @@ func TestGetServiceInfo(t *testing.T) {
server.RegisterService(&testSd, &testServer{}) server.RegisterService(&testSd, &testServer{})
info := server.GetServiceInfo() info := server.GetServiceInfo()
want := map[string]*ServiceInfo{ want := map[string]ServiceInfo{
"grpc.testing.EmptyService": { "grpc.testing.EmptyService": {
Methods: []MethodInfo{ Methods: []MethodInfo{
{ {
@ -108,6 +108,6 @@ func TestGetServiceInfo(t *testing.T) {
} }
if !reflect.DeepEqual(info, want) { if !reflect.DeepEqual(info, want) {
t.Errorf("GetServiceInfo() = %q, want %q", info, want) t.Errorf("GetServiceInfo() = %+v, want %+v", info, want)
} }
} }