move broker codec
This commit is contained in:
10
broker/codec/codec.go
Normal file
10
broker/codec/codec.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package codec
|
||||
|
||||
// Codec is used for encoding where the broker doesn't natively support
|
||||
// headers in the message type. In this case the entire message is
|
||||
// encoded as the payload
|
||||
type Codec interface {
|
||||
Marshal(interface{}) ([]byte, error)
|
||||
Unmarshal([]byte, interface{}) error
|
||||
String() string
|
||||
}
|
@@ -3,7 +3,7 @@ package json
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/micro/go-micro/broker"
|
||||
"github.com/micro/go-micro/broker/codec"
|
||||
)
|
||||
|
||||
type jsonCodec struct{}
|
||||
@@ -20,6 +20,6 @@ func (j jsonCodec) String() string {
|
||||
return "json"
|
||||
}
|
||||
|
||||
func NewCodec() broker.Codec {
|
||||
func NewCodec() codec.Codec {
|
||||
return jsonCodec{}
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
|
||||
"github.com/micro/go-micro/broker"
|
||||
"github.com/micro/go-micro/broker/codec"
|
||||
)
|
||||
|
||||
type noopCodec struct{}
|
||||
@@ -29,6 +30,6 @@ func (n noopCodec) String() string {
|
||||
return "noop"
|
||||
}
|
||||
|
||||
func NewCodec() broker.Codec {
|
||||
func NewCodec() codec.Codec {
|
||||
return noopCodec{}
|
||||
}
|
||||
|
Reference in New Issue
Block a user