responses

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromJson

func FromJson(body io.ReadCloser, status int) (interface{}, error)

This function maps and casts an HTTP response to an interface.

The `body` parameter is an io.ReadCloser object that represents the HTTP response body. The `status` parameter is an integer that represents the HTTP status code.

This function returns the mapped and casted HTTP response as an interface.

func ToJson

func ToJson(object interface{}) (string, error)

This function serializes the object to a JSON string and returns it as a string. If an error occurs during the process, it will be returned.

Types

type ErrorResponse

type ErrorResponse struct {
	// Anonymous field, to embed the Response struct (composition)
	Response
}

ErrorResponse provides a specific structure for an error response coming from a transaction.

type FailureResponse

type FailureResponse struct {
	// Anonymous field, to embed the Response struct (composition)
	Response
}

FailureResponse provides a specific structure for a failure response coming from a transaction.

type InputErrorResponse

type InputErrorResponse struct {
	// Anonymous field, to embed the Response struct (composition)
	Response
}

InputErrorResponse provides a specific structure for an input error response coming from a transaction.

type NetworkFailureResponse

type NetworkFailureResponse struct {
	// Anonymous field, to embed the Response struct (composition)
	Response
}

NetworkFailureResponse provides a specific structure for a network failure response coming from a transaction.

type NoAccessResponse

type NoAccessResponse struct {
	// Anonymous field, to embed the Response struct (composition)
	Response
}

NoAccessResponse provides a specific structure for a no access response coming from a transaction.

type NotFoundResponse

type NotFoundResponse struct {
	// Anonymous field, to embed the Response struct (composition)
	Response
}

NotFoundResponse provides a specific structure for a not found response coming from a transaction.

type PayloadResponse

type PayloadResponse struct {
	// Anonymous field, to embed the Response struct (composition)
	Response
}

PayloadResponse provides a specific structure for a payload response coming from a transaction.

type PaymentDeclinedResponse

type PaymentDeclinedResponse struct {
	// Anonymous field, to embed the Response struct (composition)
	Response
}

PaymentDeclinedResponse provides a specific structure for a payment declined response coming from a transaction.

type PreconditionalResponse

type PreconditionalResponse struct {
	// Anonymous field, to embed the Response struct (composition)
	Response
}

PreconditionalResponse provides a specific structure for a preconditional response coming from a transaction.

type Response

type Response struct {

	// Response status success
	Success bool `json:"success,omitempty"`

	// Response friendly messag
	Message string `json:"message,omitempty"`

	// Response 'action to' format
	Action string `json:"action,omitempty"`

	// Response data payload
	Data map[string]interface{} `json:"data,omitempty"`

	// Response input validation felds errors
	Errors map[string][]string `json:"errors,omitempty"`
	// contains filtered or unexported fields
}

Response provides a specific structure for a base response coming from a transaction.

func (*Response) GetData

func (response *Response) GetData(key string) interface{}

Checks if the given key has data in the response object.

The `key` parameter represents the key to check.

This function returns the data if it exists, otherwise it will return nil.

func (*Response) GetStatus

func (response *Response) GetStatus() int

This function retrieves the HTTP status code from a response.

Returns the HTTP status as an int value.

func (*Response) InputHasError

func (response *Response) InputHasError(key string) bool

Checks if the given key has an error in the response object.

The `key` parameter represents the key to check.

This function returns a boolean value indicating whether there is an error or not.

func (*Response) SetStatus

func (response *Response) SetStatus(status int) *Response

Define HTTP status code response.

The status parameter is the HTTP status code to set on the response.

This function updates the response

type SuccessResponse

type SuccessResponse struct {
	// Anonymous field, to embed the Response struct (composition)
	Response
}

SuccessResponse provides a specific structure for a success response coming from a transaction.

type TimeoutResponse

type TimeoutResponse struct {
	// Anonymous field, to embed the Response struct (composition)
	Response
}

TimeoutResponse provides a specific structure for a timeout response coming from a transaction.

Jump to

Keyboard shortcuts

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