From 8bf72a33258ff84cacdb6b935bdc513ed6bfa505 Mon Sep 17 00:00:00 2001 From: Asim Date: Wed, 6 Jan 2016 16:25:12 +0000 Subject: [PATCH] Replace map[string]string with Context for extra options. map[string]string is essentially useless. Context can store anything --- broker/options.go | 19 +++++++++++++------ client/options.go | 22 ++++++++++++++-------- cmd/options.go | 6 ++++++ options.go | 8 +++++--- registry/options.go | 7 +++++-- selector/options.go | 12 ++++++++---- server/options.go | 9 +++++---- transport/transport.go | 12 ++++++++---- 8 files changed, 64 insertions(+), 31 deletions(-) diff --git a/broker/options.go b/broker/options.go index a0309aa1..2e067e6f 100644 --- a/broker/options.go +++ b/broker/options.go @@ -1,14 +1,20 @@ package broker +import ( + "golang.org/x/net/context" +) + type Options struct { - // Other options to be used by broker implementations - Options map[string]string + // Other options for implementations of the interface + // can be stored in a context + Context context.Context } type PublishOptions struct { - // Other options to be used by broker implementations - Options map[string]string + // Other options for implementations of the interface + // can be stored in a context + Context context.Context } type SubscribeOptions struct { @@ -20,8 +26,9 @@ type SubscribeOptions struct { // receives a subset of messages. Queue string - // Other options to be used by broker implementations - Options map[string]string + // Other options for implementations of the interface + // can be stored in a context + Context context.Context } type Option func(*Options) diff --git a/client/options.go b/client/options.go index dcbffb28..25f88041 100644 --- a/client/options.go +++ b/client/options.go @@ -8,6 +8,8 @@ import ( "github.com/micro/go-micro/registry" "github.com/micro/go-micro/selector" "github.com/micro/go-micro/transport" + + "golang.org/x/net/context" ) type Options struct { @@ -22,27 +24,31 @@ type Options struct { RequestTimeout time.Duration DialTimeout time.Duration - // Other options to be used by client implementations - Options map[string]string + // Other options for implementations of the interface + // can be stored in a context + Context context.Context } type CallOptions struct { SelectOptions []selector.SelectOption - // Other options to be used by client implementations - Options map[string]string + // Other options for implementations of the interface + // can be stored in a context + Context context.Context } type PublishOptions struct { - // Other options to be used by client implementations - Options map[string]string + // Other options for implementations of the interface + // can be stored in a context + Context context.Context } type RequestOptions struct { Stream bool - // Other options to be used by client implementations - Options map[string]string + // Other options for implementations of the interface + // can be stored in a context + Context context.Context } func newOptions(options ...Option) Options { diff --git a/cmd/options.go b/cmd/options.go index cd237afe..4ecfcb7d 100644 --- a/cmd/options.go +++ b/cmd/options.go @@ -7,6 +7,8 @@ import ( "github.com/micro/go-micro/selector" "github.com/micro/go-micro/server" "github.com/micro/go-micro/transport" + + "golang.org/x/net/context" ) type Options struct { @@ -27,6 +29,10 @@ type Options struct { Registries map[string]func([]string, ...registry.Option) registry.Registry Selectors map[string]func(...selector.Option) selector.Selector 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 diff --git a/options.go b/options.go index 8c347def..9389ade6 100644 --- a/options.go +++ b/options.go @@ -8,6 +8,8 @@ import ( "github.com/micro/go-micro/registry" "github.com/micro/go-micro/server" "github.com/micro/go-micro/transport" + + "golang.org/x/net/context" ) type Options struct { @@ -22,8 +24,9 @@ type Options struct { BeforeStart []func() error AfterStop []func() error - // Alternative options for those implementing the interface - Options map[string]string + // Other options for implementations of the interface + // can be stored in a context + Context context.Context } func newOptions(opts ...Option) Options { @@ -34,7 +37,6 @@ func newOptions(opts ...Option) Options { Server: server.DefaultServer, Registry: registry.DefaultRegistry, Transport: transport.DefaultTransport, - Options: map[string]string{}, } for _, o := range opts { diff --git a/registry/options.go b/registry/options.go index ab951103..dce8676f 100644 --- a/registry/options.go +++ b/registry/options.go @@ -2,13 +2,16 @@ package registry import ( "time" + + "golang.org/x/net/context" ) type Options struct { Timeout time.Duration - // Other options to be used by registry implementations - Options map[string]string + // Other options for implementations of the interface + // can be stored in a context + Context context.Context } func Timeout(t time.Duration) Option { diff --git a/selector/options.go b/selector/options.go index d7e0a417..13973489 100644 --- a/selector/options.go +++ b/selector/options.go @@ -2,20 +2,24 @@ package selector import ( "github.com/micro/go-micro/registry" + + "golang.org/x/net/context" ) type Options struct { Registry registry.Registry - // Other options to be used by broker implementations - Options map[string]string + // Other options for implementations of the interface + // can be stored in a context + Context context.Context } type SelectOptions struct { Filters []SelectFilter - // Other options to be used by broker implementations - Options map[string]string + // Other options for implementations of the interface + // can be stored in a context + Context context.Context } // Option used to initialise the selector diff --git a/server/options.go b/server/options.go index 1ddeb7f5..c8cd16e5 100644 --- a/server/options.go +++ b/server/options.go @@ -5,6 +5,8 @@ import ( "github.com/micro/go-micro/codec" "github.com/micro/go-micro/registry" "github.com/micro/go-micro/transport" + + "golang.org/x/net/context" ) type Options struct { @@ -21,16 +23,15 @@ type Options struct { HdlrWrappers []HandlerWrapper SubWrappers []SubscriberWrapper - // Extra options settable by users. - // Used for other implementations. - Options map[string]string + // Other options for implementations of the interface + // can be stored in a context + Context context.Context } func newOptions(opt ...Option) Options { opts := Options{ Codecs: make(map[string]codec.NewCodec), Metadata: map[string]string{}, - Options: map[string]string{}, } for _, o := range opt { diff --git a/transport/transport.go b/transport/transport.go index 014e8d01..9156c649 100644 --- a/transport/transport.go +++ b/transport/transport.go @@ -2,6 +2,8 @@ package transport import ( "time" + + "golang.org/x/net/context" ) type Message struct { @@ -34,16 +36,18 @@ type Transport interface { } type Options struct { - // Other options to be used by broker implementations - Options map[string]string + // 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 to be used by broker implementations - Options map[string]string + // Other options for implementations of the interface + // can be stored in a context + Context context.Context } type Option func(*Options)