grpchttpendpoint

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDecodeRequest = errors.New("cannot decode request")

ErrDecodeRequest indicate an error occur on decoding the request.

View Source
var ErrEmptyRequestBody = errors.New("empty request body")

ErrEmptyRequestBody indicate the request body is empty.

View Source
var ErrNotImplementedInWSGHE = errors.New("not implemented in WSGHE")

ErrNotImplementedInWSGHE indicate the function is not implemented in WebSocket gRPC HTTP endpoint.

Functions

func DecodeJSONRequest

func DecodeJSONRequest(w http.ResponseWriter, r *http.Request, m proto.Message, opts *protojson.UnmarshalOptions) error

DecodeJSONRequest decodes the JSON request into the given proto message reference. The HTTP error status code will be respond if decoding failed. UnmarshalOptions opts cannot be nil.

func ErrorStatusResponse

func ErrorStatusResponse(w http.ResponseWriter, err error)

ErrorStatusResponse generate HTTP error response based on given gRPC error status.

func JSONResponseWithStatusCode

func JSONResponseWithStatusCode(w http.ResponseWriter, m proto.Message, statusCode int, opts *protojson.MarshalOptions) (err error)

JSONResponseWithStatusCode generate JSON response based on given protobuf message m with given statusCode and private Cache-Control headers enabled. MarshalOptions opts cannot be nil.

func RequestPathInBytes

func RequestPathInBytes(r *http.Request) []byte

RequestPathInBytes returns the URL path of request in bytes. Leading slashes will be removed.

Types

type ErrLoadRequest

type ErrLoadRequest struct {
	Err error
}

ErrLoadRequest indicate having issue on loading the request.

func (ErrLoadRequest) Error

func (e ErrLoadRequest) Error() string

func (ErrLoadRequest) Unwrap

func (e ErrLoadRequest) Unwrap() []error

type ErrMalformedRequest

type ErrMalformedRequest struct {
	Err error
}

ErrMalformedRequest indicate the request is malformed and cannot be decode.

func (ErrMalformedRequest) Error

func (e ErrMalformedRequest) Error() string

func (ErrMalformedRequest) Unwrap

func (e ErrMalformedRequest) Unwrap() []error

type WSGHEServerStream added in v0.1.0

type WSGHEServerStream struct {
	Ctx  context.Context
	Conn *websocket.Conn

	MarshalOpts   *protojson.MarshalOptions
	UnmarshalOpts *protojson.UnmarshalOptions
}

WSGHEServerStream provides a server-side gRPC stream interface based on WebSocket. This implementation fulfills grpc.ServerStream interface. Most function is not implemented as it is not applicable.

func (*WSGHEServerStream) Context added in v0.1.0

func (ss *WSGHEServerStream) Context() context.Context

Context returns the context for this stream.

func (*WSGHEServerStream) RecvMsg added in v0.1.0

func (ss *WSGHEServerStream) RecvMsg(m any) error

RecvMsg wrap around RecvProtoMessage(). If given message is not a protobuf message, it will return ErrNotImplementedInWSGHE.

func (*WSGHEServerStream) RecvProtoMessage added in v0.1.0

func (ss *WSGHEServerStream) RecvProtoMessage(m proto.Message) error

RecvProtoMessage receive the protobuf message from the client.

func (*WSGHEServerStream) SendHeader added in v0.1.0

func (ss *WSGHEServerStream) SendHeader(metadata.MD) error

SendHeader is not implemented.

func (*WSGHEServerStream) SendMsg added in v0.1.0

func (ss *WSGHEServerStream) SendMsg(m any) error

SendMsg wrap around SendProtoMessage(). If given message is not a protobuf message, it will return ErrNotImplementedInWSGHE.

func (*WSGHEServerStream) SendProtoMessage added in v0.1.0

func (ss *WSGHEServerStream) SendProtoMessage(m proto.Message) error

SendProtoMessage send the given protobuf message to the client.

func (*WSGHEServerStream) SetHeader added in v0.1.0

func (ss *WSGHEServerStream) SetHeader(metadata.MD) error

SetHeader is not implemented.

func (*WSGHEServerStream) SetTrailer added in v0.1.0

func (ss *WSGHEServerStream) SetTrailer(metadata.MD)

SetTrailer is not implemented.

Jump to

Keyboard shortcuts

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