add func ToByteso

This commit is contained in:
Nam Huynh 2022-12-04 23:11:51 +07:00
parent e2b22676d4
commit 756352eb19
1 changed files with 10 additions and 0 deletions

View File

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