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
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.
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 error.
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