github.com/micro/go-micro/v2@v2.9.1/transport/options.go (about) 1 package transport 2 3 import ( 4 "context" 5 "crypto/tls" 6 "time" 7 8 "github.com/micro/go-micro/v2/codec" 9 ) 10 11 type Options struct { 12 // Addrs is the list of intermediary addresses to connect to 13 Addrs []string 14 // Codec is the codec interface to use where headers are not supported 15 // by the transport and the entire payload must be encoded 16 Codec codec.Marshaler 17 // Secure tells the transport to secure the connection. 18 // In the case TLSConfig is not specified best effort self-signed 19 // certs should be used 20 Secure bool 21 // TLSConfig to secure the connection. The assumption is that this 22 // is mTLS keypair 23 TLSConfig *tls.Config 24 // Timeout sets the timeout for Send/Recv 25 Timeout time.Duration 26 // Other options for implementations of the interface 27 // can be stored in a context 28 Context context.Context 29 } 30 31 type DialOptions struct { 32 // Tells the transport this is a streaming connection with 33 // multiple calls to send/recv and that send may not even be called 34 Stream bool 35 // Timeout for dialing 36 Timeout time.Duration 37 38 // TODO: add tls options when dialling 39 // Currently set in global options 40 41 // Other options for implementations of the interface 42 // can be stored in a context 43 Context context.Context 44 } 45 46 type ListenOptions struct { 47 // TODO: add tls options when listening 48 // Currently set in global options 49 50 // Other options for implementations of the interface 51 // can be stored in a context 52 Context context.Context 53 } 54 55 // Addrs to use for transport 56 func Addrs(addrs ...string) Option { 57 return func(o *Options) { 58 o.Addrs = addrs 59 } 60 } 61 62 // Codec sets the codec used for encoding where the transport 63 // does not support message headers 64 func Codec(c codec.Marshaler) Option { 65 return func(o *Options) { 66 o.Codec = c 67 } 68 } 69 70 // Timeout sets the timeout for Send/Recv execution 71 func Timeout(t time.Duration) Option { 72 return func(o *Options) { 73 o.Timeout = t 74 } 75 } 76 77 // Use secure communication. If TLSConfig is not specified we 78 // use InsecureSkipVerify and generate a self signed cert 79 func Secure(b bool) Option { 80 return func(o *Options) { 81 o.Secure = b 82 } 83 } 84 85 // TLSConfig to be used for the transport. 86 func TLSConfig(t *tls.Config) Option { 87 return func(o *Options) { 88 o.TLSConfig = t 89 } 90 } 91 92 // Indicates whether this is a streaming connection 93 func WithStream() DialOption { 94 return func(o *DialOptions) { 95 o.Stream = true 96 } 97 } 98 99 // Timeout used when dialling the remote side 100 func WithTimeout(d time.Duration) DialOption { 101 return func(o *DialOptions) { 102 o.Timeout = d 103 } 104 }