Skip to content

Commit d640884

Browse files
committed
add option to set default content type
1 parent 8dd7603 commit d640884

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

codecs/codecs.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import (
44
"sync"
55
)
66

7+
const (
8+
JSONCodecName = "application/json"
9+
ProtoCodecName = "application/protobuf"
10+
XMLCodecName = "application/xml"
11+
)
12+
713
// Codec is an interface that encodes message on pub and decodes it on sub.
814
type Codec interface {
915
Encoder
@@ -20,9 +26,9 @@ var Register = register{codecs: make(map[string]Codec)}
2026

2127
func init() {
2228
Register.Register("", &JSONCodec{})
23-
Register.Register("application/json", &JSONCodec{})
24-
Register.Register("application/xml", &XMLCodec{})
25-
Register.Register("application/protobuf", &ProtobufCodec{})
29+
Register.Register(JSONCodecName, &JSONCodec{})
30+
Register.Register(XMLCodecName, &XMLCodec{})
31+
Register.Register(ProtoCodecName, &ProtobufCodec{})
2632
}
2733

2834
type register struct {

publisher_options.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,9 @@ func PublisherHandlersAmount(n int) PublisherOption {
6969
}
7070
}
7171
}
72+
73+
func PublisherContentType(t string) PublisherOption {
74+
return func(publisher *Publisher) {
75+
publisher.opts.defaultContentType = t
76+
}
77+
}

0 commit comments

Comments
 (0)