mirror of
https://github.com/linka-cloud/grpc.git
synced 2024-11-21 18:36:25 +00:00
add WithListener option
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
parent
b230278441
commit
9bf4e691ce
@ -127,6 +127,15 @@ func WithAddress(addr string) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithListener specifies a listener for the service.
|
||||||
|
// It can be used to specify a custom listener.
|
||||||
|
// This will override the WithAddress and WithTLSConfig options
|
||||||
|
func WithListener(lis net.Listener) Option {
|
||||||
|
return func(o *options) {
|
||||||
|
o.lis = lis
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func WithReflection(r bool) Option {
|
func WithReflection(r bool) Option {
|
||||||
return func(o *options) {
|
return func(o *options) {
|
||||||
o.reflection = r
|
o.reflection = r
|
||||||
@ -330,6 +339,7 @@ type options struct {
|
|||||||
name string
|
name string
|
||||||
version string
|
version string
|
||||||
address string
|
address string
|
||||||
|
lis net.Listener
|
||||||
|
|
||||||
reflection bool
|
reflection bool
|
||||||
health bool
|
health bool
|
||||||
|
@ -151,17 +151,21 @@ func (s *service) run() error {
|
|||||||
s.opts.address = strings.TrimPrefix(s.opts.address, "unix://")
|
s.opts.address = strings.TrimPrefix(s.opts.address, "unix://")
|
||||||
}
|
}
|
||||||
|
|
||||||
lis, err := net.Listen(network, s.opts.address)
|
if s.opts.lis == nil {
|
||||||
if err != nil {
|
lis, err := net.Listen(network, s.opts.address)
|
||||||
return err
|
if err != nil {
|
||||||
}
|
return err
|
||||||
if s.opts.tlsConfig != nil {
|
}
|
||||||
lis = tls.NewListener(lis, s.opts.tlsConfig)
|
if s.opts.tlsConfig != nil {
|
||||||
|
lis = tls.NewListener(lis, s.opts.tlsConfig)
|
||||||
|
}
|
||||||
|
s.opts.lis = lis
|
||||||
|
s.opts.address = lis.Addr().String()
|
||||||
|
} else {
|
||||||
|
s.opts.address = s.opts.lis.Addr().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
s.opts.address = lis.Addr().String()
|
mux := cmux.New(s.opts.lis)
|
||||||
|
|
||||||
mux := cmux.New(lis)
|
|
||||||
mux.SetReadTimeout(5 * time.Second)
|
mux.SetReadTimeout(5 * time.Second)
|
||||||
|
|
||||||
gLis := mux.MatchWithWriters(cmux.HTTP2MatchHeaderFieldSendSettings("content-type", "application/grpc"))
|
gLis := mux.MatchWithWriters(cmux.HTTP2MatchHeaderFieldSendSettings("content-type", "application/grpc"))
|
||||||
|
Loading…
Reference in New Issue
Block a user