add func convert between interface and bytes
This commit is contained in:
parent
756352eb19
commit
a75d3722f7
14
utils.go
14
utils.go
|
@ -42,11 +42,19 @@ func GenerateReqrepSubject(server, service, subject string) string {
|
||||||
return fmt.Sprintf("%s.reqrep.%s.%s.%s", globalConfig.StreamName, server, service, subject)
|
return fmt.Sprintf("%s.reqrep.%s.%s.%s", globalConfig.StreamName, server, service, subject)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToBytes ...
|
// InterfaceToBytes ...
|
||||||
func ToBytes(data interface{}) []byte {
|
func InterfaceToBytes(data interface{}) []byte {
|
||||||
b, err := json.Marshal(data)
|
b, err := json.Marshal(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("[natsio.ToBytes] error: %v with data: %v\n", err, data)
|
fmt.Printf("[natsio.InterfaceToBytes] error: %v with data: %v\n", err, data)
|
||||||
}
|
}
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BytesToInterface(b []byte, pointer interface{}) error {
|
||||||
|
err := json.Unmarshal(b, pointer)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("[natsio.BytesToInterface] error: %v with data: %s\n", err, string(b))
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue