protocol

package
v0.0.0-...-9f6f0cf Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPError

type HTTPError struct {
	StatusCode int
	Body       string
}

HTTPError represents an http error response

func (HTTPError) Error

func (he HTTPError) Error() string

Error returns the error string

type HTTPProtocol

type HTTPProtocol struct{}

HTTPProtocol is a struct used as a selector for request/response protocol utility methods

func HTTP

func HTTP() HTTPProtocol

HTTP returns the HTTPProtocol utilities.

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) UnprocessableEntity

func (hp HTTPProtocol) UnprocessableEntity(message string) HTTPError

UnprocessableEntity creates an UnprocessableEntity HTTPError

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

Jump to

Keyboard shortcuts

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