mirror of
				https://github.com/go-micro/go-micro.git
				synced 2025-10-30 23:27:41 +02:00 
			
		
		
		
	Replace map[string]string with Context for extra options. map[string]string is essentially useless. Context can store anything
This commit is contained in:
		| @@ -1,14 +1,20 @@ | |||||||
| package broker | package broker | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"golang.org/x/net/context" | ||||||
|  | ) | ||||||
|  |  | ||||||
| type Options struct { | type Options struct { | ||||||
|  |  | ||||||
| 	// Other options to be used by broker implementations | 	// Other options for implementations of the interface | ||||||
| 	Options map[string]string | 	// can be stored in a context | ||||||
|  | 	Context context.Context | ||||||
| } | } | ||||||
|  |  | ||||||
| type PublishOptions struct { | type PublishOptions struct { | ||||||
| 	// Other options to be used by broker implementations | 	// Other options for implementations of the interface | ||||||
| 	Options map[string]string | 	// can be stored in a context | ||||||
|  | 	Context context.Context | ||||||
| } | } | ||||||
|  |  | ||||||
| type SubscribeOptions struct { | type SubscribeOptions struct { | ||||||
| @@ -20,8 +26,9 @@ type SubscribeOptions struct { | |||||||
| 	// receives a subset of messages. | 	// receives a subset of messages. | ||||||
| 	Queue string | 	Queue string | ||||||
|  |  | ||||||
| 	// Other options to be used by broker implementations | 	// Other options for implementations of the interface | ||||||
| 	Options map[string]string | 	// can be stored in a context | ||||||
|  | 	Context context.Context | ||||||
| } | } | ||||||
|  |  | ||||||
| type Option func(*Options) | type Option func(*Options) | ||||||
|   | |||||||
| @@ -8,6 +8,8 @@ import ( | |||||||
| 	"github.com/micro/go-micro/registry" | 	"github.com/micro/go-micro/registry" | ||||||
| 	"github.com/micro/go-micro/selector" | 	"github.com/micro/go-micro/selector" | ||||||
| 	"github.com/micro/go-micro/transport" | 	"github.com/micro/go-micro/transport" | ||||||
|  |  | ||||||
|  | 	"golang.org/x/net/context" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| type Options struct { | type Options struct { | ||||||
| @@ -22,27 +24,31 @@ type Options struct { | |||||||
| 	RequestTimeout time.Duration | 	RequestTimeout time.Duration | ||||||
| 	DialTimeout    time.Duration | 	DialTimeout    time.Duration | ||||||
|  |  | ||||||
| 	// Other options to be used by client implementations | 	// Other options for implementations of the interface | ||||||
| 	Options map[string]string | 	// can be stored in a context | ||||||
|  | 	Context context.Context | ||||||
| } | } | ||||||
|  |  | ||||||
| type CallOptions struct { | type CallOptions struct { | ||||||
| 	SelectOptions []selector.SelectOption | 	SelectOptions []selector.SelectOption | ||||||
|  |  | ||||||
| 	// Other options to be used by client implementations | 	// Other options for implementations of the interface | ||||||
| 	Options map[string]string | 	// can be stored in a context | ||||||
|  | 	Context context.Context | ||||||
| } | } | ||||||
|  |  | ||||||
| type PublishOptions struct { | type PublishOptions struct { | ||||||
| 	// Other options to be used by client implementations | 	// Other options for implementations of the interface | ||||||
| 	Options map[string]string | 	// can be stored in a context | ||||||
|  | 	Context context.Context | ||||||
| } | } | ||||||
|  |  | ||||||
| type RequestOptions struct { | type RequestOptions struct { | ||||||
| 	Stream bool | 	Stream bool | ||||||
|  |  | ||||||
| 	// Other options to be used by client implementations | 	// Other options for implementations of the interface | ||||||
| 	Options map[string]string | 	// can be stored in a context | ||||||
|  | 	Context context.Context | ||||||
| } | } | ||||||
|  |  | ||||||
| func newOptions(options ...Option) Options { | func newOptions(options ...Option) Options { | ||||||
|   | |||||||
| @@ -7,6 +7,8 @@ import ( | |||||||
| 	"github.com/micro/go-micro/selector" | 	"github.com/micro/go-micro/selector" | ||||||
| 	"github.com/micro/go-micro/server" | 	"github.com/micro/go-micro/server" | ||||||
| 	"github.com/micro/go-micro/transport" | 	"github.com/micro/go-micro/transport" | ||||||
|  |  | ||||||
|  | 	"golang.org/x/net/context" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| type Options struct { | type Options struct { | ||||||
| @@ -27,6 +29,10 @@ type Options struct { | |||||||
| 	Registries map[string]func([]string, ...registry.Option) registry.Registry | 	Registries map[string]func([]string, ...registry.Option) registry.Registry | ||||||
| 	Selectors  map[string]func(...selector.Option) selector.Selector | 	Selectors  map[string]func(...selector.Option) selector.Selector | ||||||
| 	Transports map[string]func([]string, ...transport.Option) transport.Transport | 	Transports map[string]func([]string, ...transport.Option) transport.Transport | ||||||
|  |  | ||||||
|  | 	// Other options for implementations of the interface | ||||||
|  | 	// can be stored in a context | ||||||
|  | 	Context context.Context | ||||||
| } | } | ||||||
|  |  | ||||||
| // Command line Name | // Command line Name | ||||||
|   | |||||||
| @@ -8,6 +8,8 @@ import ( | |||||||
| 	"github.com/micro/go-micro/registry" | 	"github.com/micro/go-micro/registry" | ||||||
| 	"github.com/micro/go-micro/server" | 	"github.com/micro/go-micro/server" | ||||||
| 	"github.com/micro/go-micro/transport" | 	"github.com/micro/go-micro/transport" | ||||||
|  |  | ||||||
|  | 	"golang.org/x/net/context" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| type Options struct { | type Options struct { | ||||||
| @@ -22,8 +24,9 @@ type Options struct { | |||||||
| 	BeforeStart []func() error | 	BeforeStart []func() error | ||||||
| 	AfterStop   []func() error | 	AfterStop   []func() error | ||||||
|  |  | ||||||
| 	// Alternative options for those implementing the interface | 	// Other options for implementations of the interface | ||||||
| 	Options map[string]string | 	// can be stored in a context | ||||||
|  | 	Context context.Context | ||||||
| } | } | ||||||
|  |  | ||||||
| func newOptions(opts ...Option) Options { | func newOptions(opts ...Option) Options { | ||||||
| @@ -34,7 +37,6 @@ func newOptions(opts ...Option) Options { | |||||||
| 		Server:    server.DefaultServer, | 		Server:    server.DefaultServer, | ||||||
| 		Registry:  registry.DefaultRegistry, | 		Registry:  registry.DefaultRegistry, | ||||||
| 		Transport: transport.DefaultTransport, | 		Transport: transport.DefaultTransport, | ||||||
| 		Options:   map[string]string{}, |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	for _, o := range opts { | 	for _, o := range opts { | ||||||
|   | |||||||
| @@ -2,13 +2,16 @@ package registry | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"time" | 	"time" | ||||||
|  |  | ||||||
|  | 	"golang.org/x/net/context" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| type Options struct { | type Options struct { | ||||||
| 	Timeout time.Duration | 	Timeout time.Duration | ||||||
|  |  | ||||||
| 	// Other options to be used by registry implementations | 	// Other options for implementations of the interface | ||||||
| 	Options map[string]string | 	// can be stored in a context | ||||||
|  | 	Context context.Context | ||||||
| } | } | ||||||
|  |  | ||||||
| func Timeout(t time.Duration) Option { | func Timeout(t time.Duration) Option { | ||||||
|   | |||||||
| @@ -2,20 +2,24 @@ package selector | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"github.com/micro/go-micro/registry" | 	"github.com/micro/go-micro/registry" | ||||||
|  |  | ||||||
|  | 	"golang.org/x/net/context" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| type Options struct { | type Options struct { | ||||||
| 	Registry registry.Registry | 	Registry registry.Registry | ||||||
|  |  | ||||||
| 	// Other options to be used by broker implementations | 	// Other options for implementations of the interface | ||||||
| 	Options map[string]string | 	// can be stored in a context | ||||||
|  | 	Context context.Context | ||||||
| } | } | ||||||
|  |  | ||||||
| type SelectOptions struct { | type SelectOptions struct { | ||||||
| 	Filters []SelectFilter | 	Filters []SelectFilter | ||||||
|  |  | ||||||
| 	// Other options to be used by broker implementations | 	// Other options for implementations of the interface | ||||||
| 	Options map[string]string | 	// can be stored in a context | ||||||
|  | 	Context context.Context | ||||||
| } | } | ||||||
|  |  | ||||||
| // Option used to initialise the selector | // Option used to initialise the selector | ||||||
|   | |||||||
| @@ -5,6 +5,8 @@ import ( | |||||||
| 	"github.com/micro/go-micro/codec" | 	"github.com/micro/go-micro/codec" | ||||||
| 	"github.com/micro/go-micro/registry" | 	"github.com/micro/go-micro/registry" | ||||||
| 	"github.com/micro/go-micro/transport" | 	"github.com/micro/go-micro/transport" | ||||||
|  |  | ||||||
|  | 	"golang.org/x/net/context" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| type Options struct { | type Options struct { | ||||||
| @@ -21,16 +23,15 @@ type Options struct { | |||||||
| 	HdlrWrappers []HandlerWrapper | 	HdlrWrappers []HandlerWrapper | ||||||
| 	SubWrappers  []SubscriberWrapper | 	SubWrappers  []SubscriberWrapper | ||||||
|  |  | ||||||
| 	// Extra options settable by users. | 	// Other options for implementations of the interface | ||||||
| 	// Used for other implementations. | 	// can be stored in a context | ||||||
| 	Options map[string]string | 	Context context.Context | ||||||
| } | } | ||||||
|  |  | ||||||
| func newOptions(opt ...Option) Options { | func newOptions(opt ...Option) Options { | ||||||
| 	opts := Options{ | 	opts := Options{ | ||||||
| 		Codecs:   make(map[string]codec.NewCodec), | 		Codecs:   make(map[string]codec.NewCodec), | ||||||
| 		Metadata: map[string]string{}, | 		Metadata: map[string]string{}, | ||||||
| 		Options:  map[string]string{}, |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	for _, o := range opt { | 	for _, o := range opt { | ||||||
|   | |||||||
| @@ -2,6 +2,8 @@ package transport | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"time" | 	"time" | ||||||
|  |  | ||||||
|  | 	"golang.org/x/net/context" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| type Message struct { | type Message struct { | ||||||
| @@ -34,16 +36,18 @@ type Transport interface { | |||||||
| } | } | ||||||
|  |  | ||||||
| type Options struct { | type Options struct { | ||||||
| 	// Other options to be used by broker implementations | 	// Other options for implementations of the interface | ||||||
| 	Options map[string]string | 	// can be stored in a context | ||||||
|  | 	Context context.Context | ||||||
| } | } | ||||||
|  |  | ||||||
| type DialOptions struct { | type DialOptions struct { | ||||||
| 	Stream  bool | 	Stream  bool | ||||||
| 	Timeout time.Duration | 	Timeout time.Duration | ||||||
|  |  | ||||||
| 	// Other options to be used by broker implementations | 	// Other options for implementations of the interface | ||||||
| 	Options map[string]string | 	// can be stored in a context | ||||||
|  | 	Context context.Context | ||||||
| } | } | ||||||
|  |  | ||||||
| type Option func(*Options) | type Option func(*Options) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user