Add transport tls
This commit is contained in:
		| @@ -1,12 +1,16 @@ | ||||
| package transport | ||||
|  | ||||
| import ( | ||||
| 	"crypto/tls" | ||||
| 	"time" | ||||
|  | ||||
| 	"golang.org/x/net/context" | ||||
| ) | ||||
|  | ||||
| type Options struct { | ||||
| 	Secure    bool | ||||
| 	TLSConfig *tls.Config | ||||
|  | ||||
| 	// Other options for implementations of the interface | ||||
| 	// can be stored in a context | ||||
| 	Context context.Context | ||||
| @@ -16,17 +20,46 @@ type DialOptions struct { | ||||
| 	Stream  bool | ||||
| 	Timeout time.Duration | ||||
|  | ||||
| 	// 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 | ||||
|  | ||||
| 	// Other options for implementations of the interface | ||||
| 	// can be stored in a context | ||||
| 	Context context.Context | ||||
| } | ||||
|  | ||||
| // 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 | ||||
| func WithStream() DialOption { | ||||
| 	return func(o *DialOptions) { | ||||
| 		o.Stream = true | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // Timeout used when dialling the remote side | ||||
| func WithTimeout(d time.Duration) DialOption { | ||||
| 	return func(o *DialOptions) { | ||||
| 		o.Timeout = d | ||||
|   | ||||
		Reference in New Issue
	
	Block a user