mirror of
https://github.com/go-micro/go-micro.git
synced 2024-12-24 10:07:04 +02:00
move broker codec
This commit is contained in:
parent
49e5636bcd
commit
25a6849609
@ -38,15 +38,6 @@ type Subscriber interface {
|
||||
Unsubscribe() error
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
var (
|
||||
DefaultBroker Broker = newHttpBroker()
|
||||
)
|
||||
|
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{}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package broker
|
||||
import (
|
||||
"crypto/tls"
|
||||
|
||||
"github.com/micro/go-micro/broker/codec"
|
||||
"github.com/micro/go-micro/registry"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
@ -10,9 +11,8 @@ import (
|
||||
type Options struct {
|
||||
Addrs []string
|
||||
Secure bool
|
||||
Codec Codec
|
||||
Codec codec.Codec
|
||||
TLSConfig *tls.Config
|
||||
|
||||
// Other options for implementations of the interface
|
||||
// can be stored in a context
|
||||
Context context.Context
|
||||
@ -69,6 +69,14 @@ func Addrs(addrs ...string) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// Codec sets the codec used for encoding/decoding used where
|
||||
// a broker does not support headers
|
||||
func Codec(c codec.Codec) Option {
|
||||
return func(o *Options) {
|
||||
o.Codec = c
|
||||
}
|
||||
}
|
||||
|
||||
// DisableAutoAck will disable auto acking of messages
|
||||
// after they have been handled.
|
||||
func DisableAutoAck() SubscribeOption {
|
||||
@ -97,14 +105,6 @@ func Secure(b bool) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// Codec sets the codec used for encoding/decoding used where
|
||||
// a broker does not support headers
|
||||
func SetCodec(c Codec) Option {
|
||||
return func(o *Options) {
|
||||
o.Codec = c
|
||||
}
|
||||
}
|
||||
|
||||
// Specify TLS Config
|
||||
func TLSConfig(t *tls.Config) Option {
|
||||
return func(o *Options) {
|
||||
|
Loading…
Reference in New Issue
Block a user