1
0
Fork 0
mirror of https://github.com/eosswedenorg/thalos synced 2026-06-17 04:30:03 +02:00
thalos/transport/message/encoder.go

21 lines
425 B
Go

package message
import (
"encoding/json"
log "github.com/sirupsen/logrus"
)
// Encoder is a function that can encode a object to the encoded format.
type Encoder func(v any) ([]byte, error)
func Encode(v interface{}) ([]byte, bool) {
payload, err := json.Marshal(v)
if err != nil {
log.WithError(err).
WithField("v", v).
Warn("Failed to encode message to json")
return nil, false
}
return payload, true
}