From 5c7283413d6bf7796207ead27c72a28a11151075 Mon Sep 17 00:00:00 2001 From: namhq1989 Date: Mon, 19 Dec 2022 17:36:40 +0700 Subject: [PATCH] add methods MsgRespond --- utils.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/utils.go b/utils.go index 2f49fb1..c4d106a 100644 --- a/utils.go +++ b/utils.go @@ -3,6 +3,7 @@ package natsio import ( "encoding/json" "fmt" + "github.com/nats-io/nats.go" "strings" "github.com/thoas/go-funk" @@ -51,3 +52,9 @@ func BytesToInterface(b []byte, dest interface{}) error { } return err } + +func MsgRespond(msg *nats.Msg, data interface{}) { + if err := msg.Respond(InterfaceToBytes(data)); err != nil { + fmt.Printf("[natsio.MsgRespond] error when response msg %s", msg.Reply) + } +}