lint fixes (#14)

* lint fixes

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2020-08-21 14:53:21 +03:00
committed by GitHub
parent 199ff66bd4
commit c4a303190a
42 changed files with 95 additions and 178 deletions

View File

@@ -75,7 +75,6 @@ func (g *grpcClient) secure(addr string) grpc.DialOption {
func (g *grpcClient) call(ctx context.Context, addr string, req client.Request, rsp interface{}, opts client.CallOptions) error {
var header map[string]string
header = make(map[string]string)
if md, ok := metadata.FromContext(ctx); ok {
header = make(map[string]string, len(md))
for k, v := range md {
@@ -103,8 +102,10 @@ func (g *grpcClient) call(ctx context.Context, addr string, req client.Request,
var grr error
gctx, cancel := context.WithTimeout(ctx, opts.DialTimeout)
defer cancel()
grpcDialOptions := []grpc.DialOption{
grpc.WithTimeout(opts.DialTimeout),
g.secure(addr),
grpc.WithDefaultCallOptions(
grpc.MaxCallRecvMsgSize(maxRecvMsgSize),
@@ -116,7 +117,7 @@ func (g *grpcClient) call(ctx context.Context, addr string, req client.Request,
grpcDialOptions = append(grpcDialOptions, opts...)
}
cc, err := g.pool.getConn(addr, grpcDialOptions...)
cc, err := g.pool.getConn(gctx, addr, grpcDialOptions...)
if err != nil {
return errors.InternalServerError("go.micro.client", fmt.Sprintf("Error sending request: %v", err))
}
@@ -187,7 +188,6 @@ func (g *grpcClient) stream(ctx context.Context, addr string, req client.Request
wc := wrapCodec{cf}
grpcDialOptions := []grpc.DialOption{
grpc.WithTimeout(opts.DialTimeout),
g.secure(addr),
}

View File

@@ -1,6 +1,7 @@
package grpc
import (
"context"
"sync"
"time"
@@ -66,7 +67,7 @@ func newPool(size int, ttl time.Duration, idle int, ms int) *pool {
}
}
func (p *pool) getConn(addr string, opts ...grpc.DialOption) (*poolConn, error) {
func (p *pool) getConn(ctx context.Context, addr string, opts ...grpc.DialOption) (*poolConn, error) {
now := time.Now().Unix()
p.Lock()
sp, ok := p.conns[addr]
@@ -135,7 +136,7 @@ func (p *pool) getConn(addr string, opts ...grpc.DialOption) (*poolConn, error)
p.Unlock()
// create new conn
cc, err := grpc.Dial(addr, opts...)
cc, err := grpc.DialContext(ctx, addr, opts...)
if err != nil {
return nil, err
}
@@ -184,7 +185,6 @@ func (p *pool) release(addr string, conn *poolConn, err error) {
sp.idle++
}
p.Unlock()
return
}
func (conn *poolConn) Close() {
@@ -202,7 +202,6 @@ func removeConn(conn *poolConn) {
conn.next = nil
conn.in = false
conn.sp.count--
return
}
func addConnAfter(conn *poolConn, after *poolConn) {
@@ -214,5 +213,4 @@ func addConnAfter(conn *poolConn, after *poolConn) {
after.next = conn
conn.in = true
conn.sp.count++
return
}

View File

@@ -13,7 +13,7 @@ import (
func testPool(t *testing.T, size int, ttl time.Duration, idle int, ms int) {
// setup server
l, err := net.Listen("tcp", ":0")
l, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("failed to listen: %v", err)
}
@@ -24,13 +24,14 @@ func testPool(t *testing.T, size int, ttl time.Duration, idle int, ms int) {
go s.Serve(l)
defer s.Stop()
ctx := context.Background()
// zero pool
p := newPool(size, ttl, idle, ms)
for i := 0; i < 10; i++ {
// get a conn
cc, err := p.getConn(l.Addr().String(), grpc.WithInsecure())
cc, err := p.getConn(ctx, l.Addr().String(), grpc.WithInsecure())
if err != nil {
t.Fatal(err)
}

View File

@@ -27,7 +27,7 @@ func (g *greeterServer) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.
}
func TestGRPCClient(t *testing.T) {
l, err := net.Listen("tcp", ":0")
l, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("failed to listen: %v", err)
}