Replace map[string]string with Context for extra options. map[string]string is essentially useless. Context can store anything
This commit is contained in:
parent
f467902304
commit
8bf72a3325
@ -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)
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user