From 756352eb19438252ebe339e218bf1be9156601e6 Mon Sep 17 00:00:00 2001 From: Nam Huynh Date: Sun, 4 Dec 2022 23:11:51 +0700 Subject: [PATCH] add func ToByteso --- utils.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/utils.go b/utils.go index 5218be5..f93f64d 100644 --- a/utils.go +++ b/utils.go @@ -1,6 +1,7 @@ package natsio import ( + "encoding/json" "fmt" "github.com/thoas/go-funk" @@ -40,3 +41,12 @@ func GenerateJetStreamSubject(server, service, subject string) string { func GenerateReqrepSubject(server, service, subject string) string { return fmt.Sprintf("%s.reqrep.%s.%s.%s", globalConfig.StreamName, server, service, subject) } + +// ToBytes ... +func ToBytes(data interface{}) []byte { + b, err := json.Marshal(data) + if err != nil { + fmt.Printf("[natsio.ToBytes] error: %v with data: %v\n", err, data) + } + return b +}