Skip to content

Commit

Permalink
Make AckLogError accept a logger like previous signature
Browse files Browse the repository at this point in the history
  • Loading branch information
bombsimon committed May 13, 2024
1 parent 422184f commit 267b2eb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
12 changes: 6 additions & 6 deletions middleware/ack.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package middleware

import (
"context"
"log"

amqp "github.com/rabbitmq/amqp091-go"

amqprpc "github.com/0x4b53/amqp-rpc/v3"
amqp "github.com/rabbitmq/amqp091-go"
)

// OnErrFunc is the function that will be called when the middleware get an
Expand All @@ -17,9 +15,11 @@ type OnErrFunc func(err error, correlationID string)
// AckLogError is a built-in function that will log the error if any is returned
// from `Ack`.
//
// middleware := AckDelivery(AckLogError)
func AckLogError(err error, correlationID string) {
log.Printf("could not ack delivery (%s): %v\n", correlationID, err)
// middleware := AckDelivery(AckLogError(log.Printf))
func AckLogError(logFn amqprpc.LogFunc) OnErrFunc {
return func(err error, correlationID string) {
logFn("could not ack delivery (%s): %v\n", correlationID, err)
}
}

// AckDelivery is a middleware that will acknowledge the delivery after the
Expand Down
3 changes: 2 additions & 1 deletion middleware/ack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package middleware

import (
"context"
"log"
"testing"

amqp "github.com/rabbitmq/amqp091-go"
Expand Down Expand Up @@ -30,7 +31,7 @@ func TestAckDelivery(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
acknowledger := &amqprpc.MockAcknowledger{}

handler := AckDelivery(func(_ error, _ string) {})(tt.handler)
handler := AckDelivery(AckLogError(log.Printf))(tt.handler)

rw := amqprpc.NewResponseWriter(&amqp.Publishing{})
d := amqp.Delivery{Acknowledger: acknowledger}
Expand Down

0 comments on commit 267b2eb

Please sign in to comment.