httpo

package module
v0.0.0-...-836e728 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2022 License: MIT Imports: 1 Imported by: 12

Documentation

Overview

Package httpo provides methods to construct API response and send with gin context

Index

Constants

View Source
const (

	// Occurs when token is expired
	TokenExpired = 4031

	// Occurs when token is invalid, for example, signed by wrong signature or is malformed
	TokenInvalid = 4033

	// Occurs when signatures public key doesn't match to the one which was used while requesting challenge
	SignatureDenied = 4034

	// The header doesn't contain Authorization header or it is empty
	AuthHeaderMissing = 4001

	// The provided string is not valid base64
	InvalidBase64 = 4002

	// The provided wallet address is not compatible to the chain
	WalletAddressInvalid = 4003

	// User trying to refer doesn't exist in database
	UserNotFound = 4041

	// FlowID trying to refer doesn't exist in database
	FlowIdNotFound = 4042

	// Account trying to refer in chain doesn't exist, this means that account doesn't have any in or out transactions and therefore it has 0 balance
	AccountNotFound = 4043
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiResponse

type ApiResponse struct {
	// Custom status code
	StatusCode int `json:"status,omitempty"`

	Error string `json:"error,omitempty"`

	// Message in case of success
	Message string      `json:"message,omitempty"`
	Payload interface{} `json:"payload,omitempty"`
}

ApiResponse defines struct used for http response

func NewErrorResponse

func NewErrorResponse(customStatusCode int, errorStr string) *ApiResponse

NewSuccessResponse returns ApiResponse for error

func NewSuccessResponse

func NewSuccessResponse(customStatusCode int, message string, payload interface{}) *ApiResponse

NewSuccessResponse returns ApiResponse for success

func (*ApiResponse) Send

func (apiRes *ApiResponse) Send(c *gin.Context, statusCode int)

Sends ApiResponse with gin context and standard statusCode

func (*ApiResponse) SendD

func (apiRes *ApiResponse) SendD(c *gin.Context)

Sends ApiResponse with gin context and with customStatusCode as standard one

Jump to

Keyboard shortcuts

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