gateway

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2023 License: BSD-3-Clause Imports: 11 Imported by: 0

README

Gateway

This repo contains a JSON marshaler suitable for use with the gRPC-Gateway when using gogo/protobuf types.

License

95% of the code is copied from the gRPC-Gateway project, so their license applies.

Documentation

Overview

Package gateway contains marshaling code extracted from github.com/grpc-ecosystem/grpc-gateway/runtime and altered to depend on gogo versions of the proto and jsonpb packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPBodyMarshaler

type HTTPBodyMarshaler struct {
	runtime.Marshaler
}

HTTPBodyMarshaler is a Marshaler which supports marshaling of a google.api.HttpBody message as the full response body if it is the actual message used as the response. If not, then this will simply fallback to the Marshaler specified as its default Marshaler.

func (*HTTPBodyMarshaler) ContentType

func (h *HTTPBodyMarshaler) ContentType() string

ContentType implementation to keep backwards compatability with marshal interface

func (*HTTPBodyMarshaler) ContentTypeFromMessage

func (h *HTTPBodyMarshaler) ContentTypeFromMessage(v interface{}) string

ContentTypeFromMessage in case v is a google.api.HttpBody message it returns its specified content type otherwise fall back to the default Marshaler.

func (*HTTPBodyMarshaler) Marshal

func (h *HTTPBodyMarshaler) Marshal(v interface{}) ([]byte, error)

Marshal marshals "v" by returning the body bytes if v is a google.api.HttpBody message, otherwise it falls back to the default Marshaler.

type JSONPb

type JSONPb jsonpb.Marshaler

JSONPb is a runtime.Marshaler which marshals/unmarshals into/from JSON with "github.com/gogo/protobuf/jsonpb".

func (*JSONPb) ContentType

func (*JSONPb) ContentType() string

ContentType always returns "application/json".

func (*JSONPb) Delimiter

func (j *JSONPb) Delimiter() []byte

Delimiter for newline encoded JSON streams.

func (*JSONPb) Marshal

func (j *JSONPb) Marshal(v interface{}) ([]byte, error)

Marshal marshals "v" into JSON.

func (*JSONPb) NewDecoder

func (j *JSONPb) NewDecoder(r io.Reader) runtime.Decoder

NewDecoder returns a runtime.Decoder which reads JSON stream from "r".

func (*JSONPb) NewEncoder

func (j *JSONPb) NewEncoder(w io.Writer) runtime.Encoder

NewEncoder returns an Encoder which writes JSON stream into "w".

func (*JSONPb) Unmarshal

func (j *JSONPb) Unmarshal(data []byte, v interface{}) error

Unmarshal unmarshals JSON "data" into "v". Currently it can only marshal proto.Message.

type Proto

type Proto struct {
	// CustomContentType overrides the default Content-Type
	// of "application/octet-stream".
	CustomContentType string
}

Proto is a runtime.Marshaller which marshals/unmarshals into/from serialize proto bytes

func (*Proto) ContentType

func (p *Proto) ContentType() string

ContentType returns the Content-Type. If CustomContentType is empty, it returns "application/octet-stream".

func (*Proto) Marshal

func (*Proto) Marshal(value interface{}) ([]byte, error)

Marshal marshals "value" into Proto

func (*Proto) NewDecoder

func (p *Proto) NewDecoder(reader io.Reader) runtime.Decoder

NewDecoder returns a Decoder which reads proto stream from "reader".

func (*Proto) NewEncoder

func (p *Proto) NewEncoder(writer io.Writer) runtime.Encoder

NewEncoder returns an Encoder which writes proto stream into "writer".

func (*Proto) Unmarshal

func (*Proto) Unmarshal(data []byte, value interface{}) error

Unmarshal unmarshals proto "data" into "value"

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL