Documentation ¶
Index ¶
- Variables
- func DecodeJSONRequest(w http.ResponseWriter, r *http.Request, m proto.Message, ...) error
- func ErrorStatusResponse(w http.ResponseWriter, err error)
- func JSONResponseWithStatusCode(w http.ResponseWriter, m proto.Message, statusCode int, ...) (err error)
- func RequestPathInBytes(r *http.Request) []byte
- type ErrLoadRequest
- type ErrMalformedRequest
- type WSGHEServerStream
- func (ss *WSGHEServerStream) Context() context.Context
- func (ss *WSGHEServerStream) RecvMsg(m any) error
- func (ss *WSGHEServerStream) RecvProtoMessage(m proto.Message) error
- func (ss *WSGHEServerStream) SendHeader(metadata.MD) error
- func (ss *WSGHEServerStream) SendMsg(m any) error
- func (ss *WSGHEServerStream) SendProtoMessage(m proto.Message) error
- func (ss *WSGHEServerStream) SetHeader(metadata.MD) error
- func (ss *WSGHEServerStream) SetTrailer(metadata.MD)
Constants ¶
This section is empty.
Variables ¶
var ErrDecodeRequest = errors.New("cannot decode request")
ErrDecodeRequest indicate an error occur on decoding the request.
var ErrEmptyRequestBody = errors.New("empty request body")
ErrEmptyRequestBody indicate the request body is empty.
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 ¶
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.