diff --git a/go.mod b/go.mod index 828deb2..7eb59e4 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,8 @@ module github.com/unistack-org/micro-network-transport-grpc go 1.15 require ( - github.com/golang/protobuf v1.4.2 - github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20200922101738-21d5ca1cddc1 + github.com/golang/protobuf v1.4.3 + github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20201105212509-72bbbe381783 google.golang.org/grpc v1.31.1 google.golang.org/protobuf v1.25.0 ) diff --git a/go.sum b/go.sum index da19db1..9e327db 100644 --- a/go.sum +++ b/go.sum @@ -109,6 +109,8 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= @@ -253,17 +255,32 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/timewasted/linode v0.0.0-20160829202747-37e84520dcf7/go.mod h1:imsgLplxEC/etjIhdr3dNzV3JeT27LbVu5pYWm0JCBY= github.com/transip/gotransip v0.0.0-20190812104329-6d8d9179b66f/go.mod h1:i0f4R4o2HM0m3DZYQWsj6/MEowD57VzoH0v3d7igeFY= github.com/uber-go/atomic v1.3.2/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g= +github.com/unistack-org/micro-codec-bytes v0.0.0-20200827104921-3616a69473a6/go.mod h1:g5sOI8TWgGZiVHe8zoUPdtz7+0oLnqTnfBoai6Qb7jE= +github.com/unistack-org/micro-codec-bytes v0.0.0-20200828083432-4e49e953d844 h1:5b1yuSllbsMm/9fUIlIXSr8DbsKT/sAKSCgOx6+SAfI= github.com/unistack-org/micro-codec-bytes v0.0.0-20200828083432-4e49e953d844/go.mod h1:g5sOI8TWgGZiVHe8zoUPdtz7+0oLnqTnfBoai6Qb7jE= +github.com/unistack-org/micro-codec-json v0.0.0-20201102222734-a29c895ec05c h1:RtcNaK8rQSl7xAoy1W437dvZLCVjSC6e4JcolepSQs0= +github.com/unistack-org/micro-codec-json v0.0.0-20201102222734-a29c895ec05c/go.mod h1:dG5aUyhBv+ebOl/UFW2Aj2GTfVxxXWi6AcynpePOAhQ= +github.com/unistack-org/micro-codec-jsonrpc v0.0.0-20201102222451-ff6a69988bcd h1:qXSiEfVnCgrwTHYvAnEPSHEai3+5EUH9ZYovLpxGDwg= +github.com/unistack-org/micro-codec-jsonrpc v0.0.0-20201102222451-ff6a69988bcd/go.mod h1:PFyvkGhavl+3tEPgOaLAhoJJX4/webVGW59BSOXDfNM= +github.com/unistack-org/micro-codec-proto v0.0.0-20201102222202-769c2d6a4b92 h1:1rPDBu7Nwo3ZL6r6H5rj7qNchHSdBF4zcewAeTUEMC4= +github.com/unistack-org/micro-codec-proto v0.0.0-20201102222202-769c2d6a4b92/go.mod h1:31JMo683bBQ+uN9YufpUU6ESHphyx3DFmTXEnjpJV9Y= +github.com/unistack-org/micro-codec-protorpc v0.0.0-20201102222610-3a343898c077 h1:uK7owL8TPSwoQiDM1V/0swmgCEepSQKXoi8GEnGxtlU= +github.com/unistack-org/micro-codec-protorpc v0.0.0-20201102222610-3a343898c077/go.mod h1:Ct4uAVZaDEyBZj9Q0poDkbzu6zKXUCcSqJkv/MWPpeI= +github.com/unistack-org/micro-config-cmd v0.0.0-20200828075439-d859b9d7265b/go.mod h1:6pm1cadbwsFcEW1ZbV5Fp0i3goR3TNfROMNSPih3I8k= github.com/unistack-org/micro-config-cmd v0.0.0-20200909210346-ec89783dc46c/go.mod h1:6pm1cadbwsFcEW1ZbV5Fp0i3goR3TNfROMNSPih3I8k= github.com/unistack-org/micro-config-cmd v0.0.0-20200909210755-6e7e85eeab34/go.mod h1:fT1gYn+TtfVZZ5tNx56bZIncJjmlji66g7GKdWua5hE= github.com/unistack-org/micro-config-cmd v0.0.0-20200920140133-0853deb2e5dc h1:hHAU3rgeiA0LaudfNdMLf9/jkOBeFxvJdnwXevviZF8= github.com/unistack-org/micro-config-cmd v0.0.0-20200920140133-0853deb2e5dc/go.mod h1:il8nz4ZEcX3Usyfrtwy+YtQcb7xSUSFJdSe8PBJ9gOA= +github.com/unistack-org/micro-config-cmd v0.0.0-20201028144621-5a55f1aad70a h1:VjlqP1qZkjC0Chmx5MKFPIbtSCigeICFDf8vaLZGh9o= +github.com/unistack-org/micro-config-cmd v0.0.0-20201028144621-5a55f1aad70a/go.mod h1:MzMg+qh1wORZwYtg5AVgFkNFrXVVbdPKW7s/Is+A994= github.com/unistack-org/micro/v3 v3.0.0-20200827083227-aa99378adc6e h1:oMUWUSX7pQNdujHQRp4rlDg3+MCah05uYc2+ouz+V2Q= github.com/unistack-org/micro/v3 v3.0.0-20200827083227-aa99378adc6e/go.mod h1:rPQbnry3nboAnMczj8B1Gzlcyv/HYoMZLgd3/3nttJ4= +github.com/unistack-org/micro/v3 v3.0.0-gamma/go.mod h1:iEtpu3wTYCRs3pQ3VsFEO7JBO4lOMpkOwMyrpZyIDPo= github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20200909210629-caec730248b1/go.mod h1:mmqHR9WelHUXqg2mELjsQ+FJHcWs6mNmXg+wEYO2T3c= github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20200920135754-1cbd1d2bad83/go.mod h1:HUzMG4Mcy97958VxWTg8zuazZgwQ/aoLZ8wtBVONwRE= -github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20200922101738-21d5ca1cddc1 h1:Ki+acK9YEn6OuqOQkZZPrGEslmeMvS9kPSObU01yn2E= -github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20200922101738-21d5ca1cddc1/go.mod h1:aL+8VhSXpx0SuEeXPOWUo5BgS7kyvWYobeXFay90UUM= +github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20200922103357-4c4fa00a5d94/go.mod h1:aL+8VhSXpx0SuEeXPOWUo5BgS7kyvWYobeXFay90UUM= +github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20201105212509-72bbbe381783 h1:+wqZNIa2PZRndVP2mW+wY4gNGZ3ZHSHNZxlr2gMysrQ= +github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20201105212509-72bbbe381783/go.mod h1:LFvCXGOgcLIj2k/8eL71TpIpcJBN2SXXAUx8U6dz9Rw= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/vultr/govultr v0.1.4/go.mod h1:9H008Uxr/C4vFNGLqKx232C206GL0PBHzOP0809bGNA= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= diff --git a/grpc.go b/grpc.go index dd9a893..275af69 100644 --- a/grpc.go +++ b/grpc.go @@ -22,6 +22,7 @@ type grpcTransportListener struct { listener net.Listener secure bool tls *tls.Config + opts transport.ListenOptions } func (t *grpcTransportListener) Addr() string { @@ -53,14 +54,8 @@ func (t *grpcTransportListener) Accept(fn func(transport.Socket)) error { return srv.Serve(t.listener) } -func (t *grpcTransport) Dial(addr string, opts ...transport.DialOption) (transport.Client, error) { - dopts := transport.DialOptions{ - Timeout: transport.DefaultDialTimeout, - } - - for _, opt := range opts { - opt(&dopts) - } +func (t *grpcTransport) Dial(ctx context.Context, addr string, opts ...transport.DialOption) (transport.Client, error) { + dopts := transport.NewDialOptions(opts...) options := []grpc.DialOption{} @@ -78,7 +73,7 @@ func (t *grpcTransport) Dial(addr string, opts ...transport.DialOption) (transpo } // dial the server - ctx, cancel := context.WithTimeout(context.Background(), dopts.Timeout) + ctx, cancel := context.WithTimeout(ctx, dopts.Timeout) defer cancel() conn, err := grpc.DialContext(ctx, addr, options...) if err != nil { @@ -100,11 +95,8 @@ func (t *grpcTransport) Dial(addr string, opts ...transport.DialOption) (transpo }, nil } -func (t *grpcTransport) Listen(addr string, opts ...transport.ListenOption) (transport.Listener, error) { - var options transport.ListenOptions - for _, o := range opts { - o(&options) - } +func (t *grpcTransport) Listen(ctx context.Context, addr string, opts ...transport.ListenOption) (transport.Listener, error) { + options := transport.NewListenOptions(opts...) ln, err := mnet.Listen(addr, func(addr string) (net.Listener, error) { return net.Listen("tcp", addr) @@ -117,6 +109,7 @@ func (t *grpcTransport) Listen(addr string, opts ...transport.ListenOption) (tra listener: ln, tls: t.opts.TLSConfig, secure: t.opts.Secure, + opts: options, }, nil } diff --git a/handler.go b/handler.go index 441ac29..b364d42 100644 --- a/handler.go +++ b/handler.go @@ -31,7 +31,8 @@ func (m *microTransport) Stream(ts pb.Transport_StreamServer) (err error) { defer func() { if r := recover(); r != nil { - logger.Error(r, string(debug.Stack())) + logger.Error("panic recovered: ", r) + logger.Error(string(debug.Stack())) sock.Close() err = errors.InternalServerError("go.micro.transport", "panic recovered: %v", r) }