many improvements with options and noop stuff
* add many options helpers * fix noop client to allow publish messages to topic in broker * fix noop server to allow registering in registry * fix noop server to allow subscribe to topic in broker * fix new service initialization Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
70
network/transport/noop.go
Normal file
70
network/transport/noop.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package transport
|
||||
|
||||
type NoopTransport struct {
|
||||
opts Options
|
||||
}
|
||||
|
||||
func (t *NoopTransport) Init(opts ...Option) error {
|
||||
for _, o := range opts {
|
||||
o(&t.opts)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *NoopTransport) Options() Options {
|
||||
return t.opts
|
||||
}
|
||||
|
||||
func (t *NoopTransport) Dial(addr string, opts ...DialOption) (Client, error) {
|
||||
options := NewDialOptions(opts...)
|
||||
return &noopClient{opts: options}, nil
|
||||
}
|
||||
|
||||
func (t *NoopTransport) Listen(addr string, opts ...ListenOption) (Listener, error) {
|
||||
options := NewListenOptions(opts...)
|
||||
return &noopListener{opts: options}, nil
|
||||
}
|
||||
|
||||
func (t *NoopTransport) String() string {
|
||||
return "noop"
|
||||
}
|
||||
|
||||
type noopClient struct {
|
||||
opts DialOptions
|
||||
}
|
||||
|
||||
func (c *noopClient) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *noopClient) Local() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (c *noopClient) Remote() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (c *noopClient) Recv(*Message) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *noopClient) Send(*Message) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type noopListener struct {
|
||||
opts ListenOptions
|
||||
}
|
||||
|
||||
func (l *noopListener) Addr() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (l *noopListener) Accept(fn func(Socket)) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *noopListener) Close() error {
|
||||
return nil
|
||||
}
|
@@ -106,6 +106,12 @@ func Logger(l logger.Logger) Option {
|
||||
}
|
||||
}
|
||||
|
||||
func Context(ctx context.Context) Option {
|
||||
return func(o *Options) {
|
||||
o.Context = ctx
|
||||
}
|
||||
}
|
||||
|
||||
// Codec sets the codec used for encoding where the transport
|
||||
// does not support message headers
|
||||
func Codec(c codec.Marshaler) Option {
|
||||
|
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
DefaultTransport Transport
|
||||
DefaultTransport Transport = &NoopTransport{opts: NewOptions()}
|
||||
)
|
||||
|
||||
// Transport is an interface which is used for communication between
|
||||
|
Reference in New Issue
Block a user