Skip to content

Commit

Permalink
chore(storage): remove gob encoding on rabbitmq (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
42atomys committed Jun 12, 2022
1 parent 6a62512 commit dbf27d1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 25 deletions.
12 changes: 2 additions & 10 deletions pkg/storage/rabbitmq/rabbitmq.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package rabbitmq

import (
"bytes"
"encoding/gob"
"fmt"

"github.com/streadway/amqp"

Expand Down Expand Up @@ -93,21 +92,14 @@ func (c storage) Name() string {
// @param value that will be pushed
// @return an error if the push failed
func (c storage) Push(value interface{}) error {
var buf bytes.Buffer

enc := gob.NewEncoder(&buf)
if err := enc.Encode(value); err != nil {
return err
}

if err := c.channel.Publish(
c.config.Exchange,
c.routingKey.Name,
c.config.Mandatory,
c.config.Immediate,
amqp.Publishing{
ContentType: c.config.ContentType(),
Body: []byte(buf.Bytes()),
Body: []byte(fmt.Sprintf("%v", value)),
}); err != nil {
return err
}
Expand Down
16 changes: 1 addition & 15 deletions pkg/storage/rabbitmq/rabbitmq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,7 @@ func (suite *RabbitMQSetupTestSuite) TestRabbitMQNewStorage() {
}

func (suite *RabbitMQSetupTestSuite) TestRabbitMQPush() {
newClient, _ := NewStorage(map[string]interface{}{
"databaseUrl": "amqp://user:[email protected]:5672",
"queueName": "hello",
"contentType": "application/json",
"durable": false,
"deleteWhenUnused": false,
"exclusive": false,
"noWait": false,
"mandatory": false,
"immediate": false,
})
err := newClient.Push(func() {})
assert.Error(suite.T(), err)

newClient, err = NewStorage(map[string]interface{}{
newClient, err := NewStorage(map[string]interface{}{
"databaseUrl": "amqp://user:[email protected]:5672",
"queueName": "hello",
"contentType": "text/plain",
Expand Down

0 comments on commit dbf27d1

Please sign in to comment.