Documentation
¶
Index ¶
- type HTTPError
- type HTTPProtocol
- func (hp HTTPProtocol) BadRequest(message string) HTTPError
- func (hp HTTPProtocol) InternalServerError(message string) HTTPError
- func (hp HTTPProtocol) NotFound() HTTPError
- func (hp HTTPProtocol) ToResponse(data interface{}, err error) *HTTPResponse
- func (hp HTTPProtocol) WriteData(w http.ResponseWriter, data interface{})
- func (hp HTTPProtocol) WriteDataWithMessage(w http.ResponseWriter, data interface{}, message string)
- func (hp HTTPProtocol) WriteDataWithMessageAndWarning(w http.ResponseWriter, data interface{}, message string, warning string)
- func (hp HTTPProtocol) WriteDataWithWarning(w http.ResponseWriter, data interface{}, warning string)
- func (hp HTTPProtocol) WriteError(w http.ResponseWriter, err HTTPError)
- func (hp HTTPProtocol) WriteProtoWithMessage(w http.ResponseWriter, data proto.Message)
- func (hp HTTPProtocol) WriteResponse(w http.ResponseWriter, r *HTTPResponse)
- type HTTPResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HTTPProtocol ¶
type HTTPProtocol struct{}
HTTPProtocol is a struct used as a selector for request/response protocol utility methods
func (HTTPProtocol) BadRequest ¶
func (hp HTTPProtocol) BadRequest(message string) HTTPError
BadRequest creates a BadRequest HTTPError
func (HTTPProtocol) InternalServerError ¶
func (hp HTTPProtocol) InternalServerError(message string) HTTPError
InternalServerError creates an InternalServerError HTTPError
func (HTTPProtocol) NotFound ¶
func (hp HTTPProtocol) NotFound() HTTPError
NotFound creates a NotFound HTTPError
func (HTTPProtocol) ToResponse ¶
func (hp HTTPProtocol) ToResponse(data interface{}, err error) *HTTPResponse
ToResponse accepts a data payload and/or error to encode into a new HTTPResponse instance. Responses which should not contain an error should pass nil for err.
func (HTTPProtocol) WriteData ¶
func (hp HTTPProtocol) WriteData(w http.ResponseWriter, data interface{})
WriteData wraps the data payload in an HTTPResponse and writes the resulting response using the http.ResponseWriter
func (HTTPProtocol) WriteDataWithMessage ¶
func (hp HTTPProtocol) WriteDataWithMessage(w http.ResponseWriter, data interface{}, message string)
WriteDataWithMessage writes the data payload similiar to WriteData except it provides an additional string message.
func (HTTPProtocol) WriteDataWithMessageAndWarning ¶
func (hp HTTPProtocol) WriteDataWithMessageAndWarning(w http.ResponseWriter, data interface{}, message string, warning string)
WriteDataWithMessageAndWarning writes the data payload similiar to WriteData except it provides a warning and additional message string.
func (HTTPProtocol) WriteDataWithWarning ¶
func (hp HTTPProtocol) WriteDataWithWarning(w http.ResponseWriter, data interface{}, warning string)
WriteDataWithWarning writes the data payload similiar to WriteData except it provides an additional warning message.
func (HTTPProtocol) WriteError ¶
func (hp HTTPProtocol) WriteError(w http.ResponseWriter, err HTTPError)
WriteError wraps the HTTPError in a HTTPResponse and writes it via http.ResponseWriter
func (HTTPProtocol) WriteProtoWithMessage ¶
func (hp HTTPProtocol) WriteProtoWithMessage(w http.ResponseWriter, data proto.Message)
WriteProtoWithMessage uses the protojson package to convert proto3 response to json response and return it to the requester. Proto3 drops messages with default values but overriding the param EmitUnpopulated to true it returns default values in the Json response payload. If error is encountered it sent InternalServerError and the error why the json conversion failed.
func (HTTPProtocol) WriteResponse ¶
func (hp HTTPProtocol) WriteResponse(w http.ResponseWriter, r *HTTPResponse)
WriteResponse writes the provided HTTPResponse instance via http.ResponseWriter
type HTTPResponse ¶
type HTTPResponse struct { Code int `json:"code"` Data interface{} `json:"data"` Message string `json:"message,omitempty"` Warning string `json:"warning,omitempty"` }
HTTPResponse represents a data envelope for our HTTP messaging