Merge pull request #743 from menghanl/go_vet

Fix go vet
This commit is contained in:
Qi Zhao
2016-06-30 15:10:19 -07:00
committed by GitHub
11 changed files with 32 additions and 28 deletions

View File

@ -158,7 +158,7 @@ type roundRobin struct {
func (rr *roundRobin) watchAddrUpdates() error { func (rr *roundRobin) watchAddrUpdates() error {
updates, err := rr.w.Next() updates, err := rr.w.Next()
if err != nil { if err != nil {
grpclog.Println("grpc: the naming watcher stops working due to %v.", err) grpclog.Printf("grpc: the naming watcher stops working due to %v.\n", err)
return err return err
} }
rr.mu.Lock() rr.mu.Lock()

View File

@ -60,7 +60,7 @@ type byteBufCodec struct {
func (byteBufCodec) Marshal(v interface{}) ([]byte, error) { func (byteBufCodec) Marshal(v interface{}) ([]byte, error) {
b, ok := v.(*[]byte) b, ok := v.(*[]byte)
if !ok { if !ok {
return nil, fmt.Errorf("failed to marshal: %v is not type of *[]byte") return nil, fmt.Errorf("failed to marshal: %v is not type of *[]byte", v)
} }
return *b, nil return *b, nil
} }
@ -68,7 +68,7 @@ func (byteBufCodec) Marshal(v interface{}) ([]byte, error) {
func (byteBufCodec) Unmarshal(data []byte, v interface{}) error { func (byteBufCodec) Unmarshal(data []byte, v interface{}) error {
b, ok := v.(*[]byte) b, ok := v.(*[]byte)
if !ok { if !ok {
return fmt.Errorf("failed to marshal: %v is not type of *[]byte") return fmt.Errorf("failed to marshal: %v is not type of *[]byte", v)
} }
*b = data *b = data
return nil return nil
@ -138,8 +138,6 @@ func (s *workerServer) RunServer(stream testpb.WorkerService_RunServerServer) er
return err return err
} }
} }
return nil
} }
func (s *workerServer) RunClient(stream testpb.WorkerService_RunClientServer) error { func (s *workerServer) RunClient(stream testpb.WorkerService_RunClientServer) error {
@ -191,13 +189,11 @@ func (s *workerServer) RunClient(stream testpb.WorkerService_RunClientServer) er
return err return err
} }
} }
return nil
} }
func (s *workerServer) CoreCount(ctx context.Context, in *testpb.CoreRequest) (*testpb.CoreResponse, error) { func (s *workerServer) CoreCount(ctx context.Context, in *testpb.CoreRequest) (*testpb.CoreResponse, error) {
grpclog.Printf("core count: %v", runtime.NumCPU()) grpclog.Printf("core count: %v", runtime.NumCPU())
return &testpb.CoreResponse{int32(runtime.NumCPU())}, nil return &testpb.CoreResponse{Cores: int32(runtime.NumCPU())}, nil
} }
func (s *workerServer) QuitWorker(ctx context.Context, in *testpb.Void) (*testpb.Void, error) { func (s *workerServer) QuitWorker(ctx context.Context, in *testpb.Void) (*testpb.Void, error) {

View File

@ -116,7 +116,7 @@ func (t TLSInfo) AuthType() string {
// tlsCreds is the credentials required for authenticating a connection using TLS. // tlsCreds is the credentials required for authenticating a connection using TLS.
type tlsCreds struct { type tlsCreds struct {
// TLS configuration // TLS configuration
config tls.Config config *tls.Config
} }
func (c tlsCreds) Info() ProtocolInfo { func (c tlsCreds) Info() ProtocolInfo {
@ -158,7 +158,7 @@ func (c *tlsCreds) ClientHandshake(addr string, rawConn net.Conn, timeout time.D
} }
c.config.ServerName = addr[:colonPos] c.config.ServerName = addr[:colonPos]
} }
conn := tls.Client(rawConn, &c.config) conn := tls.Client(rawConn, c.config)
if timeout == 0 { if timeout == 0 {
err = conn.Handshake() err = conn.Handshake()
} else { } else {
@ -177,7 +177,7 @@ func (c *tlsCreds) ClientHandshake(addr string, rawConn net.Conn, timeout time.D
} }
func (c *tlsCreds) ServerHandshake(rawConn net.Conn) (net.Conn, AuthInfo, error) { func (c *tlsCreds) ServerHandshake(rawConn net.Conn) (net.Conn, AuthInfo, error) {
conn := tls.Server(rawConn, &c.config) conn := tls.Server(rawConn, c.config)
if err := conn.Handshake(); err != nil { if err := conn.Handshake(); err != nil {
rawConn.Close() rawConn.Close()
return nil, nil, err return nil, nil, err
@ -187,7 +187,7 @@ func (c *tlsCreds) ServerHandshake(rawConn net.Conn) (net.Conn, AuthInfo, error)
// NewTLS uses c to construct a TransportCredentials based on TLS. // NewTLS uses c to construct a TransportCredentials based on TLS.
func NewTLS(c *tls.Config) TransportCredentials { func NewTLS(c *tls.Config) TransportCredentials {
tc := &tlsCreds{*c} tc := &tlsCreds{c}
tc.config.NextProtos = alpnProtoStr tc.config.NextProtos = alpnProtoStr
return tc return tc
} }

View File

@ -115,12 +115,12 @@ func runRecordRoute(client pb.RouteGuideClient) {
// runRouteChat receives a sequence of route notes, while sending notes for various locations. // runRouteChat receives a sequence of route notes, while sending notes for various locations.
func runRouteChat(client pb.RouteGuideClient) { func runRouteChat(client pb.RouteGuideClient) {
notes := []*pb.RouteNote{ notes := []*pb.RouteNote{
{&pb.Point{0, 1}, "First message"}, {&pb.Point{Latitude: 0, Longitude: 1}, "First message"},
{&pb.Point{0, 2}, "Second message"}, {&pb.Point{Latitude: 0, Longitude: 2}, "Second message"},
{&pb.Point{0, 3}, "Third message"}, {&pb.Point{Latitude: 0, Longitude: 3}, "Third message"},
{&pb.Point{0, 1}, "Fourth message"}, {&pb.Point{Latitude: 0, Longitude: 1}, "Fourth message"},
{&pb.Point{0, 2}, "Fifth message"}, {&pb.Point{Latitude: 0, Longitude: 2}, "Fifth message"},
{&pb.Point{0, 3}, "Sixth message"}, {&pb.Point{Latitude: 0, Longitude: 3}, "Sixth message"},
} }
stream, err := client.RouteChat(context.Background()) stream, err := client.RouteChat(context.Background())
if err != nil { if err != nil {
@ -192,7 +192,7 @@ func main() {
printFeature(client, &pb.Point{0, 0}) printFeature(client, &pb.Point{0, 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{400000000, -750000000}, &pb.Point{420000000, -730000000}}) printFeatures(client, &pb.Rectangle{&pb.Point{Latitude: 400000000, Longitude: -750000000}, &pb.Point{Latitude: 420000000, Longitude: -730000000}})
// RecordRoute // RecordRoute
runRecordRoute(client) runRecordRoute(client)

View File

@ -253,7 +253,7 @@ func (s *serverReflectionServer) fileDescEncodingContainingSymbol(name string) (
// Metadata not valid. // Metadata not valid.
enc, ok := meta.([]byte) enc, ok := meta.([]byte)
if !ok { if !ok {
return nil, fmt.Errorf("invalid file descriptor for symbol: %v") return nil, fmt.Errorf("invalid file descriptor for symbol: %v", name)
} }
fd, err = s.decodeFileDesc(enc) fd, err = s.decodeFileDesc(enc)

View File

@ -162,7 +162,7 @@ func (s *server) GetAllGauges(in *metricspb.EmptyMessage, stream metricspb.Metri
defer s.mutex.RUnlock() defer s.mutex.RUnlock()
for name, gauge := range s.gauges { for name, gauge := range s.gauges {
if err := stream.Send(&metricspb.GaugeResponse{Name: name, Value: &metricspb.GaugeResponse_LongValue{gauge.get()}}); err != nil { if err := stream.Send(&metricspb.GaugeResponse{Name: name, Value: &metricspb.GaugeResponse_LongValue{LongValue: gauge.get()}}); err != nil {
return err return err
} }
} }
@ -175,7 +175,7 @@ func (s *server) GetGauge(ctx context.Context, in *metricspb.GaugeRequest) (*met
defer s.mutex.RUnlock() defer s.mutex.RUnlock()
if g, ok := s.gauges[in.Name]; ok { if g, ok := s.gauges[in.Name]; ok {
return &metricspb.GaugeResponse{Name: in.Name, Value: &metricspb.GaugeResponse_LongValue{g.get()}}, nil return &metricspb.GaugeResponse{Name: in.Name, Value: &metricspb.GaugeResponse_LongValue{LongValue: g.get()}}, nil
} }
return nil, grpc.Errorf(codes.InvalidArgument, "gauge with name %s not found", in.Name) return nil, grpc.Errorf(codes.InvalidArgument, "gauge with name %s not found", in.Name)
} }

View File

@ -1887,7 +1887,7 @@ func testClientRequestBodyError_Cancel_StreamingInput(t *testing.T, e env) {
t.Fatal("timeout waiting for error") t.Fatal("timeout waiting for error")
} }
if se, ok := got.(transport.StreamError); !ok || se.Code != codes.Canceled { if se, ok := got.(transport.StreamError); !ok || se.Code != codes.Canceled {
t.Errorf("error = %#v; want transport.StreamError with code Canceled") t.Errorf("error = %#v; want transport.StreamError with code Canceled", got)
} }
}) })
} }

View File

@ -312,7 +312,7 @@ func (ht *serverHandlerTransport) HandleStreams(startStream func(*Stream)) {
Addr: ht.RemoteAddr(), Addr: ht.RemoteAddr(),
} }
if req.TLS != nil { if req.TLS != nil {
pr.AuthInfo = credentials.TLSInfo{*req.TLS} pr.AuthInfo = credentials.TLSInfo{State: *req.TLS}
} }
ctx = metadata.NewContext(ctx, ht.headerMD) ctx = metadata.NewContext(ctx, ht.headerMD)
ctx = peer.NewContext(ctx, pr) ctx = peer.NewContext(ctx, pr)

View File

@ -175,7 +175,10 @@ func newHTTP2Client(addr string, opts *ConnectOptions) (_ ClientTransport, err e
return nil, ConnectionErrorf("transport: preface mismatch, wrote %d bytes; want %d", n, len(clientPreface)) return nil, ConnectionErrorf("transport: preface mismatch, wrote %d bytes; want %d", n, len(clientPreface))
} }
if initialWindowSize != defaultWindowSize { if initialWindowSize != defaultWindowSize {
err = t.framer.writeSettings(true, http2.Setting{http2.SettingInitialWindowSize, uint32(initialWindowSize)}) err = t.framer.writeSettings(true, http2.Setting{
ID: http2.SettingInitialWindowSize,
Val: uint32(initialWindowSize),
})
} else { } else {
err = t.framer.writeSettings(true) err = t.framer.writeSettings(true)
} }

View File

@ -100,10 +100,15 @@ func newHTTP2Server(conn net.Conn, maxStreams uint32, authInfo credentials.AuthI
if maxStreams == 0 { if maxStreams == 0 {
maxStreams = math.MaxUint32 maxStreams = math.MaxUint32
} else { } else {
settings = append(settings, http2.Setting{http2.SettingMaxConcurrentStreams, maxStreams}) settings = append(settings, http2.Setting{
ID: http2.SettingMaxConcurrentStreams,
Val: maxStreams,
})
} }
if initialWindowSize != defaultWindowSize { if initialWindowSize != defaultWindowSize {
settings = append(settings, http2.Setting{http2.SettingInitialWindowSize, uint32(initialWindowSize)}) settings = append(settings, http2.Setting{
ID: http2.SettingInitialWindowSize,
Val: uint32(initialWindowSize)})
} }
if err := framer.writeSettings(true, settings...); err != nil { if err := framer.writeSettings(true, settings...); err != nil {
return nil, ConnectionErrorf("transport: %v", err) return nil, ConnectionErrorf("transport: %v", err)

View File

@ -370,7 +370,7 @@ func TestGracefulClose(t *testing.T) {
go func() { go func() {
defer wg.Done() defer wg.Done()
if _, err := ct.NewStream(context.Background(), callHdr); err != ErrConnClosing { if _, err := ct.NewStream(context.Background(), callHdr); err != ErrConnClosing {
t.Errorf("%v.NewStream(_, _) = _, %v, want _, %v", err, ErrConnClosing) t.Errorf("%v.NewStream(_, _) = _, %v, want _, %v", ct, err, ErrConnClosing)
} }
}() }()
} }