add methods MsgRespond

This commit is contained in:
namhq1989 2022-12-19 17:36:40 +07:00
parent 32b13fbf86
commit 5c7283413d
1 changed files with 7 additions and 0 deletions

View File

@ -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)
}
}