Move options over
This commit is contained in:
		
							
								
								
									
										34
									
								
								transport/options.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								transport/options.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,34 @@ | |||||||
|  | package transport | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"time" | ||||||
|  |  | ||||||
|  | 	"golang.org/x/net/context" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | type Options struct { | ||||||
|  | 	// Other options for implementations of the interface | ||||||
|  | 	// can be stored in a context | ||||||
|  | 	Context context.Context | ||||||
|  | } | ||||||
|  |  | ||||||
|  | type DialOptions struct { | ||||||
|  | 	Stream  bool | ||||||
|  | 	Timeout time.Duration | ||||||
|  |  | ||||||
|  | 	// Other options for implementations of the interface | ||||||
|  | 	// can be stored in a context | ||||||
|  | 	Context context.Context | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func WithStream() DialOption { | ||||||
|  | 	return func(o *DialOptions) { | ||||||
|  | 		o.Stream = true | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func WithTimeout(d time.Duration) DialOption { | ||||||
|  | 	return func(o *DialOptions) { | ||||||
|  | 		o.Timeout = d | ||||||
|  | 	} | ||||||
|  | } | ||||||
| @@ -2,8 +2,6 @@ package transport | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"time" | 	"time" | ||||||
|  |  | ||||||
| 	"golang.org/x/net/context" |  | ||||||
| ) | ) | ||||||
|  |  | ||||||
| type Message struct { | type Message struct { | ||||||
| @@ -35,21 +33,6 @@ type Transport interface { | |||||||
| 	String() string | 	String() string | ||||||
| } | } | ||||||
|  |  | ||||||
| type Options struct { |  | ||||||
| 	// Other options for implementations of the interface |  | ||||||
| 	// can be stored in a context |  | ||||||
| 	Context context.Context |  | ||||||
| } |  | ||||||
|  |  | ||||||
| type DialOptions struct { |  | ||||||
| 	Stream  bool |  | ||||||
| 	Timeout time.Duration |  | ||||||
|  |  | ||||||
| 	// Other options for implementations of the interface |  | ||||||
| 	// can be stored in a context |  | ||||||
| 	Context context.Context |  | ||||||
| } |  | ||||||
|  |  | ||||||
| type Option func(*Options) | type Option func(*Options) | ||||||
|  |  | ||||||
| type DialOption func(*DialOptions) | type DialOption func(*DialOptions) | ||||||
| @@ -60,18 +43,6 @@ var ( | |||||||
| 	DefaultDialTimeout = time.Second * 5 | 	DefaultDialTimeout = time.Second * 5 | ||||||
| ) | ) | ||||||
|  |  | ||||||
| func WithStream() DialOption { |  | ||||||
| 	return func(o *DialOptions) { |  | ||||||
| 		o.Stream = true |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
|  |  | ||||||
| func WithTimeout(d time.Duration) DialOption { |  | ||||||
| 	return func(o *DialOptions) { |  | ||||||
| 		o.Timeout = d |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
|  |  | ||||||
| func NewTransport(addrs []string, opt ...Option) Transport { | func NewTransport(addrs []string, opt ...Option) Transport { | ||||||
| 	return newHttpTransport(addrs, opt...) | 	return newHttpTransport(addrs, opt...) | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user