Skip to content

Commit dfdf7c0

Browse files
authored
fix: encoding typo (#12)
1 parent 9caeeca commit dfdf7c0

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

encoding.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ import (
88
headerVal "github.com/bxcodec/goqueue/headers/value"
99
)
1010

11+
// EncoderFn is a function type that encodes a message into a byte slice.
12+
// It takes a context and a message as input and returns the encoded data and an error (if any).
1113
type EncoderFn func(ctx context.Context, m Message) (data []byte, err error)
14+
15+
// DecoderFn is a function type that decodes a byte slice into a Message.
16+
// It takes a context and a byte slice as input and returns a Message and an error.
1217
type DecoderFn func(ctx context.Context, data []byte) (m Message, err error)
1318

1419
var (
@@ -28,27 +33,37 @@ var (
2833
)
2934

3035
var (
31-
GoquEncodingMap = sync.Map{}
36+
// goQueueEncodingMap is a concurrent-safe map used for encoding in GoQueue.
37+
goQueueEncodingMap = sync.Map{}
3238
)
3339

34-
func AddGoquEncoding(contentType headerVal.ContentType, encoding *Encoding) {
35-
GoquEncodingMap.Store(contentType, encoding)
40+
// AddGoQueueEncoding stores the given encoding for the specified content type in the goQueueEncodingMap.
41+
// The goQueueEncodingMap is a concurrent-safe map that maps content types to encodings.
42+
// The content type is specified by the `contentType` parameter, and the encoding is specified by the `encoding` parameter.
43+
// This function is typically used to register custom encodings for specific content types in the GoQueue library.
44+
func AddGoQueueEncoding(contentType headerVal.ContentType, encoding *Encoding) {
45+
goQueueEncodingMap.Store(contentType, encoding)
3646
}
3747

38-
func GetGoquEncoding(contentType headerVal.ContentType) (res *Encoding, ok bool) {
39-
if encoding, ok := GoquEncodingMap.Load(contentType); ok {
48+
// GetGoQueueEncoding returns the encoding associated with the given content type.
49+
// It looks up the encoding in the goQueueEncodingMap and returns it along with a boolean value indicating if the encoding was found.
50+
// If the encoding is not found, it returns nil and false.
51+
func GetGoQueueEncoding(contentType headerVal.ContentType) (res *Encoding, ok bool) {
52+
if encoding, ok := goQueueEncodingMap.Load(contentType); ok {
4053
return encoding.(*Encoding), ok
4154
}
4255
return nil, false
4356
}
4457

58+
// Encoding represents an encoding configuration for a specific content type.
4559
type Encoding struct {
46-
ContentType headerVal.ContentType
47-
Encode EncoderFn
48-
Decode DecoderFn
60+
ContentType headerVal.ContentType // The content type associated with this encoding.
61+
Encode EncoderFn // The encoding function used to encode data.
62+
Decode DecoderFn // The decoding function used to decode data.
4963
}
5064

5165
var (
66+
// JSONEncoding represents the encoding configuration for JSON.
5267
JSONEncoding = &Encoding{
5368
ContentType: headerVal.ContentTypeJSON,
5469
Encode: JSONEncoder,

publisher/rabbitmq/publisher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (r *rabbitMQ) buildPublisher() goqueue.PublisherFunc {
9999
m.ServiceAgent = headerVal.RabbitMQ
100100
m.Timestamp = timestamp
101101
m.ID = id
102-
encoder, ok := goqueue.GetGoquEncoding(m.ContentType)
102+
encoder, ok := goqueue.GetGoQueueEncoding(m.ContentType)
103103
if !ok {
104104
encoder = goqueue.DefaultEncoding
105105
}

0 commit comments

Comments
 (0)