Files
paralus/components/common/pkg/gateway/json.go
2021-12-28 14:23:52 +05:30

50 lines
1.1 KiB
Go

package gateway
import (
"io"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/segmentio/encoding/json"
)
const (
jsonContentType string = "application/json"
)
// rafayJSON is the rafay object to json marshaller
type rafayJSON struct {
}
// NewRafayJSON returns new grpc gateway rafay json marshaller
func NewRafayJSON() runtime.Marshaler {
return &rafayJSON{}
}
// Marshal marshals "v" into byte sequence.
func (m *rafayJSON) Marshal(v interface{}) ([]byte, error) {
return json.Marshal(v)
}
// Unmarshal unmarshals "data" into "v".
// "v" must be a pointer value.
func (m *rafayJSON) Unmarshal(b []byte, v interface{}) error {
return json.Unmarshal(b, v)
}
// NewDecoder returns a Decoder which reads byte sequence from "r".
func (m *rafayJSON) NewDecoder(r io.Reader) runtime.Decoder {
return json.NewDecoder(r)
}
// NewEncoder returns an Encoder which writes bytes sequence into "w".
func (m *rafayJSON) NewEncoder(w io.Writer) runtime.Encoder {
return json.NewEncoder(w)
}
// ContentType returns the Content-Type which this marshaler is responsible for.
func (m *rafayJSON) ContentType(v interface{}) string {
return jsonContentType
}