common

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2021 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorTypeNone     = iota
	ErrorTypeInternal = iota
	ErrorTypeClient   = iota
)

Variables

This section is empty.

Functions

func ChainError

func ChainError(message string, err error) error

ChainError will combine the error message and the message together in an easy to read manner.

Types

type BasicResponse

type BasicResponse struct {
	Success bool `json:"success"`
}

BasicResponse represents a response with a simple true/false success field.

func NewSuccessResponse

func NewSuccessResponse() (int, BasicResponse)

NewSuccessResponse returns an http OK status and a success basic response.

type CustomError

type CustomError struct {
	Type int
	// contains filtered or unexported fields
}

CustomError is an error with an added type field to determine how it should be handled.

func ClientError

func ClientError(message string) CustomError

ClientError returns a CustomError with type ErrorTypeClient and the provided message.

func InternalError

func InternalError() CustomError

InternalError returns a CustomError with type ErrorTypeInternal and an internal error message.

func NoError

func NoError() CustomError

NoError returns a CustomError with type ErrorTypeNone.

type DataResponse

type DataResponse struct {
	Success bool        `json:"success"`
	Data    interface{} `json:"data"`
}

DataResponse represents a response with a true/false success field and generic data.

func NewSuccessDataResponse

func NewSuccessDataResponse(data interface{}) (int, DataResponse)

NewSuccessDataResponse return an http OK status and a new DataResponse with the provided data.

type ErrorResponse

type ErrorResponse struct {
	Success bool   `json:"success"`
	Error   string `json:"error"`
}

ErrorResponse represents a response with a true/false success field and an error message.

func NewBadRequestResponse

func NewBadRequestResponse(err string) (int, ErrorResponse)

NewBadRequestResponse returns an http BadRequest status and a new error response with the provided error message.

func NewErrorResponse

func NewErrorResponse(err string) ErrorResponse

NewErrorResponse creates a new ErrorResponse with a false success field and the provided error message.

func NewInsufficientPermissionsErrorResponse

func NewInsufficientPermissionsErrorResponse() (int, ErrorResponse)

NewInsufficientPermissionsErrorResponse returns an http StatusForbidden status and a new error response with an insufficient permissions error message.

func NewInternalServerErrorResponse

func NewInternalServerErrorResponse() (int, ErrorResponse)

NewInternalServerErrorResponse returns an http StatusInternalServerError status and a new error response with an internal error message.

Jump to

Keyboard shortcuts

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