Compare commits

...

2 Commits

Author SHA1 Message Date
bcd7f6a551 codec: fix noop codec to handle *broker.Message
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2021-01-29 16:07:21 +03:00
925b3af46b register: fix options
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2021-01-29 15:06:47 +03:00
2 changed files with 12 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
package codec
import (
"encoding/json"
"io"
"io/ioutil"
)
@@ -40,7 +41,7 @@ func (c *noopCodec) ReadBody(conn io.Reader, b interface{}) error {
case *Frame:
v.Data = buf
default:
return ErrInvalidMessage
return json.Unmarshal(buf, v)
}
return nil
@@ -64,7 +65,11 @@ func (c *noopCodec) Write(conn io.Writer, m *Message, b interface{}) error {
case []byte:
v = vb
default:
return ErrInvalidMessage
var err error
v, err = json.Marshal(vb)
if err != nil {
return err
}
}
_, err := conn.Write(v)
return err
@@ -98,11 +103,11 @@ func (c *noopCodec) Marshal(v interface{}) ([]byte, error) {
case *Message:
return ve.Body, nil
}
return nil, ErrInvalidMessage
return json.Marshal(v)
}
func (c *noopCodec) Unmarshal(d []byte, v interface{}) error {
var err error
if v == nil {
return nil
}
@@ -119,9 +124,7 @@ func (c *noopCodec) Unmarshal(d []byte, v interface{}) error {
ve.Data = d
case *Message:
ve.Body = d
default:
err = ErrInvalidMessage
}
return err
return json.Unmarshal(d, v)
}

View File

@@ -246,13 +246,13 @@ func DeregisterDomain(d string) DeregisterOption {
}
}
func GetContext(ctx context.Context) LookupOption {
func LookupContext(ctx context.Context) LookupOption {
return func(o *LookupOptions) {
o.Context = ctx
}
}
func GetDomain(d string) LookupOption {
func LookupDomain(d string) LookupOption {
return func(o *LookupOptions) {
o.Domain = d
}