Add pluggable codec support

This commit is contained in:
Asim
2015-11-25 19:50:05 +00:00
parent 04e07f4b39
commit 12a1e1eeda
8 changed files with 248 additions and 64 deletions

View File

@@ -7,6 +7,7 @@ import (
)
type options struct {
codecs map[string]CodecFunc
broker broker.Broker
registry registry.Registry
transport transport.Transport
@@ -19,7 +20,9 @@ type options struct {
}
func newOptions(opt ...Option) options {
var opts options
opts := options{
codecs: make(map[string]CodecFunc),
}
for _, o := range opt {
o(&opts)
@@ -116,6 +119,12 @@ func Broker(b broker.Broker) Option {
}
}
func Codec(contentType string, cf CodecFunc) Option {
return func(o *options) {
o.codecs[contentType] = cf
}
}
func Registry(r registry.Registry) Option {
return func(o *options) {
o.registry = r