accept Listen option in grpc server (#1201)

This commit is contained in:
Asim Aslam
2020-02-15 14:09:24 +00:00
committed by Vasiliy Tolstov
parent 816bfec4a0
commit 471d2205bd
2 changed files with 35 additions and 5 deletions

View File

@@ -3,6 +3,7 @@ package grpc
import (
"context"
"crypto/tls"
"net"
"github.com/micro/go-micro/v2/broker"
"github.com/micro/go-micro/v2/codec"
@@ -14,9 +15,10 @@ import (
)
type codecsKey struct{}
type tlsAuth struct{}
type maxMsgSizeKey struct{}
type grpcOptions struct{}
type netListener struct{}
type maxMsgSizeKey struct{}
type tlsAuth struct{}
// gRPC Codec to be used to encode/decode requests for a given content type
func Codec(contentType string, c encoding.Codec) server.Option {
@@ -43,6 +45,16 @@ func AuthTLS(t *tls.Config) server.Option {
}
}
// Listener specifies the net.Listener to use instead of the default
func Listener(l net.Listener) server.Option {
return func(o *server.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, netListener{}, l)
}
}
// Options to be used to configure gRPC options
func Options(opts ...grpc.ServerOption) server.Option {
return func(o *server.Options) {