gateway

package
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 49 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FieldMaskFromRequestBody

func FieldMaskFromRequestBody(r io.Reader, msg proto.Message) (*fieldmask.FieldMask, error)

FieldMaskFromRequestBody creates a FieldMask printing all complete paths from the JSON body.

func HTTPStatusCode

func HTTPStatusCode(c codes.Code) int

func HTTPStatusFromCode

func HTTPStatusFromCode(code codes.Code) int

HTTPStatusFromCode converts a gRPC error code into the corresponding HTTP response status. See: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto

func PopulateFieldFromPath

func PopulateFieldFromPath(msg proto.Message, fieldPathString, value string) error

PopulateFieldFromPath sets a value in a nested Protobuf structure.

func PopulateQueryParameters

func PopulateQueryParameters(msg proto.Message, values url.Values, filter *utilities.DoubleArray) error

PopulateQueryParameters parses query parameters into "msg" using current query parser

Types

type Codec

type Codec interface {
	encoding.Codec
	// MarshalAppend appends the marshaled form of v to b and returns the result.
	MarshalAppend([]byte, interface{}) ([]byte, error)
}

Codec defines the interface used to encode and decode messages.

type CodecJSON

CodecJSON is a Codec implementation with protobuf json format.

func (CodecJSON) Marshal

func (c CodecJSON) Marshal(v interface{}) ([]byte, error)

func (CodecJSON) MarshalAppend

func (c CodecJSON) MarshalAppend(b []byte, v interface{}) ([]byte, error)

func (CodecJSON) Name

func (CodecJSON) Name() string

func (CodecJSON) ReadNext

func (c CodecJSON) ReadNext(b []byte, r io.Reader, limit int) ([]byte, int, error)

ReadNext reads the length of the message around the json object. It reads until it finds a matching number of braces. It does not validate the JSON.

func (CodecJSON) Unmarshal

func (c CodecJSON) Unmarshal(data []byte, v interface{}) error

func (CodecJSON) WriteNext

func (c CodecJSON) WriteNext(w io.Writer, b []byte) (int, error)

WriteNext writes the raw JSON message to w without any size prefix.

type CodecProto

type CodecProto struct {
	proto.MarshalOptions
}

CodecProto is a Codec implementation with protobuf binary format.

func (CodecProto) Marshal

func (c CodecProto) Marshal(v interface{}) ([]byte, error)

func (CodecProto) MarshalAppend

func (c CodecProto) MarshalAppend(b []byte, v interface{}) ([]byte, error)

func (CodecProto) Name

func (CodecProto) Name() string

Name == "proto" overwritting internal proto codec

func (CodecProto) ReadNext

func (c CodecProto) ReadNext(b []byte, r io.Reader, limit int) ([]byte, int, error)

ReadNext reads a varint size-delimited wire-format message from r.

func (CodecProto) Unmarshal

func (CodecProto) Unmarshal(data []byte, v interface{}) error

func (CodecProto) WriteNext

func (c CodecProto) WriteNext(w io.Writer, b []byte) (int, error)

WriteNext writes the length of the message encoded as 4 byte unsigned integer and then writes the message to w.

type Compressor

type Compressor interface {
	encoding.Compressor
}

Compressor is used to compress and decompress messages. Based on grpc/encoding.

type CompressorGzip

type CompressorGzip struct {
	Level *int
	// contains filtered or unexported fields
}

CompressorGzip implements the Compressor interface. Based on grpc/encoding/gzip.

func (*CompressorGzip) Compress

func (c *CompressorGzip) Compress(w io.Writer) (io.WriteCloser, error)

Compress implements the Compressor interface.

func (*CompressorGzip) Decompress

func (c *CompressorGzip) Decompress(r io.Reader) (io.Reader, error)

Decompress implements the Compressor interface.

func (*CompressorGzip) Name

func (*CompressorGzip) Name() string

Name returns gzip.

type DefaultQueryParser

type DefaultQueryParser struct{}

DefaultQueryParser is a QueryParameterParser which implements the default query parameters parsing behavior.

See https://github.com/grpc-ecosystem/grpc-gateway/issues/2632 for more context.

func (*DefaultQueryParser) Parse

func (*DefaultQueryParser) Parse(msg proto.Message, values url.Values, filter *utilities.DoubleArray) error

Parse populates "values" into "msg". A value is ignored if its key starts with one of the elements in "filter".

type Gateway

type Gateway interface {
	grpc.ClientConnInterface
	SetUnaryInterceptor(interceptor grpc.UnaryServerInterceptor)
	SetStreamInterceptor(interceptor grpc.StreamServerInterceptor)

	SetRequestDecoder(protoreflect.FullName, func(ctx *fiber.Ctx, msg proto.Message) error)
	SetResponseEncoder(protoreflect.FullName, func(ctx *fiber.Ctx, msg proto.Message) error)
	RegisterService(sd *grpc.ServiceDesc, ss interface{})

	Handler(*fiber.Ctx) error
	ServeHTTP(http.ResponseWriter, *http.Request)
	GetRouteMethods() []*routex.RouteTarget
}

type Mux

type Mux struct {
	// contains filtered or unexported fields
}

func NewMux

func NewMux(opts ...MuxOption) *Mux

func (*Mux) GetRouteMethods

func (m *Mux) GetRouteMethods() []*routex.RouteTarget

func (*Mux) Handler

func (m *Mux) Handler(ctx *fiber.Ctx) error

func (*Mux) Invoke

func (m *Mux) Invoke(ctx context.Context, method string, args, reply any, opts ...grpc.CallOption) error

func (*Mux) NewStream

func (m *Mux) NewStream(ctx context.Context, desc *grpc.StreamDesc, method string, opts ...grpc.CallOption) (grpc.ClientStream, error)

func (*Mux) RegisterService

func (m *Mux) RegisterService(sd *grpc.ServiceDesc, ss interface{})

RegisterService satisfies grpc.ServiceRegistrar for generated service code hooks.

func (*Mux) ServeHTTP

func (m *Mux) ServeHTTP(writer http.ResponseWriter, request *http.Request)

func (*Mux) SetRequestDecoder

func (m *Mux) SetRequestDecoder(name protoreflect.FullName, f func(ctx *fiber.Ctx, msg proto.Message) error)

func (*Mux) SetResponseEncoder

func (m *Mux) SetResponseEncoder(name protoreflect.FullName, f func(ctx *fiber.Ctx, msg proto.Message) error)

func (*Mux) SetStreamInterceptor

func (m *Mux) SetStreamInterceptor(interceptor grpc.StreamServerInterceptor)

SetStreamInterceptor configures the in-process channel to use the given server interceptor for streaming RPCs when dispatching.

func (*Mux) SetUnaryInterceptor

func (m *Mux) SetUnaryInterceptor(interceptor grpc.UnaryServerInterceptor)

type MuxOption

type MuxOption func(*muxOptions)

MuxOption is an option for a mux.

func CodecOption

func CodecOption(contentType string, c Codec) MuxOption

CodecOption registers a codec for the given content type.

func CompressorOption

func CompressorOption(contentEncoding string, c Compressor) MuxOption

CompressorOption registers a compressor for the given content encoding.

func ConnectionTimeoutOption

func ConnectionTimeoutOption(d time.Duration) MuxOption

func FilesOption

func FilesOption(f *protoregistry.Files) MuxOption

func MaxReceiveMessageSizeOption

func MaxReceiveMessageSizeOption(s int) MuxOption

func MaxSendMessageSizeOption

func MaxSendMessageSizeOption(s int) MuxOption

type QueryParameterParser

type QueryParameterParser interface {
	Parse(msg proto.Message, values url.Values, filter *utilities.DoubleArray) error
}

QueryParameterParser defines interface for all query parameter parsers

type RouteTarget

type RouteTarget = routex.RouteTarget

func GetRouterTarget

func GetRouterTarget(mux *Mux, kind, path string) (*RouteTarget, error)

type StreamCodec

type StreamCodec interface {
	Codec

	// ReadNext returns the size of the next message appended to buf.
	// ReadNext reads from r until either it has read a complete message or
	// encountered an error and returns all the data read from r.
	// The message is contained in dst[:n].
	// Excess data read from r is stored in dst[n:].
	ReadNext(buf []byte, r io.Reader, limit int) (dst []byte, n int, err error)
	// WriteNext writes the message to w with a size aware encoding
	// returning the number of bytes written.
	WriteNext(w io.Writer, src []byte) (n int, err error)
}

StreamCodec is used in streaming RPCs where the message boundaries are determined by the codec.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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