2016-01-17 00:28:57 +00:00
|
|
|
package transport
|
|
|
|
|
|
|
|
import (
|
2018-03-03 11:53:52 +00:00
|
|
|
"context"
|
2016-01-18 00:10:04 +00:00
|
|
|
"crypto/tls"
|
2016-01-17 00:28:57 +00:00
|
|
|
"time"
|
|
|
|
|
2016-12-06 18:56:57 +00:00
|
|
|
"github.com/micro/go-micro/transport/codec"
|
2016-01-17 00:28:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Options struct {
|
2016-03-15 22:25:32 +00:00
|
|
|
Addrs []string
|
2016-12-06 18:56:57 +00:00
|
|
|
Codec codec.Codec
|
2016-01-18 00:10:04 +00:00
|
|
|
Secure bool
|
|
|
|
TLSConfig *tls.Config
|
2016-08-01 16:31:27 +01:00
|
|
|
// Timeout sets the timeout for Send/Recv
|
|
|
|
Timeout time.Duration
|
2016-01-17 00:28:57 +00:00
|
|
|
// Other options for implementations of the interface
|
|
|
|
// can be stored in a context
|
|
|
|
Context context.Context
|
|
|
|
}
|
|
|
|
|
|
|
|
type DialOptions struct {
|
|
|
|
Stream bool
|
|
|
|
Timeout time.Duration
|
|
|
|
|
2016-01-18 00:10:04 +00:00
|
|
|
// TODO: add tls options when dialling
|
|
|
|
// Currently set in global options
|
|
|
|
|
|
|
|
// Other options for implementations of the interface
|
|
|
|
// can be stored in a context
|
|
|
|
Context context.Context
|
|
|
|
}
|
|
|
|
|
|
|
|
type ListenOptions struct {
|
|
|
|
// TODO: add tls options when listening
|
|
|
|
// Currently set in global options
|
|
|
|
|
2016-01-17 00:28:57 +00:00
|
|
|
// Other options for implementations of the interface
|
|
|
|
// can be stored in a context
|
|
|
|
Context context.Context
|
|
|
|
}
|
|
|
|
|
2016-03-15 22:25:32 +00:00
|
|
|
// Addrs to use for transport
|
|
|
|
func Addrs(addrs ...string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Addrs = addrs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-06 18:56:57 +00:00
|
|
|
// Codec sets the codec used for encoding where the transport
|
|
|
|
// does not support message headers
|
|
|
|
func Codec(c codec.Codec) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Codec = c
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-01 16:31:27 +01:00
|
|
|
// Timeout sets the timeout for Send/Recv execution
|
|
|
|
func Timeout(t time.Duration) Option {
|
2016-07-28 18:38:17 +01:00
|
|
|
return func(o *Options) {
|
2016-08-01 16:31:27 +01:00
|
|
|
o.Timeout = t
|
2016-07-28 18:38:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-18 00:10:04 +00:00
|
|
|
// Use secure communication. If TLSConfig is not specified we
|
|
|
|
// use InsecureSkipVerify and generate a self signed cert
|
|
|
|
func Secure(b bool) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Secure = b
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TLSConfig to be used for the transport.
|
|
|
|
func TLSConfig(t *tls.Config) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.TLSConfig = t
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Indicates whether this is a streaming connection
|
2016-01-17 00:28:57 +00:00
|
|
|
func WithStream() DialOption {
|
|
|
|
return func(o *DialOptions) {
|
|
|
|
o.Stream = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-18 00:10:04 +00:00
|
|
|
// Timeout used when dialling the remote side
|
2016-01-17 00:28:57 +00:00
|
|
|
func WithTimeout(d time.Duration) DialOption {
|
|
|
|
return func(o *DialOptions) {
|
|
|
|
o.Timeout = d
|
|
|
|
}
|
|
|
|
}
|