response

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIResponse

type APIResponse struct {
	Name        string `json:"name"`
	Description string `json:"description"`
}

APIResponse repsent the API response to return from Pokemon endpoints. Its fields are intended for JSON marshalling and unmarshalling purpose.

func NewAPIResponse

func NewAPIResponse(name, description string) *APIResponse

func (*APIResponse) SendResponseTO added in v0.0.2

func (ar *APIResponse) SendResponseTO(w http.ResponseWriter)

SendResponseTO sends the APIResponse contents as a HTTP response in the JSON form with the appropriate HTTP status code.

type ErrorResponse added in v0.0.2

type ErrorResponse struct {
	Error string `json:"error"`
	Code  int    `json:"code"`
}

ErrorResponse repsent the API error to return from Pokemon endpoints. Its fields are intended for JSON marshalling and unmarshalling purpose.

func (*ErrorResponse) WriteErrorTo added in v0.0.2

func (er *ErrorResponse) WriteErrorTo(w http.ResponseWriter)

ErrorResponse sends the ErrorResponse contents as a HTTP response in the JSON form with the appropriate HTTP status code.

type ServiceResponse

type ServiceResponse struct {
	Content   string
	Error     error
	ErrorCode int
}

ServiceResponse to represent the response from the different services integrations

func NewError

func NewError(err error) *ServiceResponse

NewError creates the ServiceResponse with error value to represent only an error

func NewErrorCode

func NewErrorCode(code int, err error) *ServiceResponse

NewErrorCode creates the ServiceResponse with error value and code to represent only an error message and the error code from service integration responses.

func NewSuccess

func NewSuccess(content string) *ServiceResponse

NewSuccess creates the ServiceResponse to to represnet the response body from service integration response.

func (*ServiceResponse) ToErrorResponse added in v0.0.2

func (sr *ServiceResponse) ToErrorResponse() *ErrorResponse

ToErrorResponse create the ErrorResponse type to from the error fields of ServiceResponse. The ErrorResponse is used to represent the API error response.

Jump to

Keyboard shortcuts

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