utils

package
v0.0.0-...-993f9dd Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Countries = []Country{}/* 250 elements not displayed */
View Source
var Currencies = map[string]Currency{}/* 120 elements not displayed */

Functions

func CalculatePriceTaxAmount

func CalculatePriceTaxAmount(price float64, taxRate float64, includesTax bool) float64

func ConvertMiddleware

func ConvertMiddleware(m []func(fiber.Ctx) error) []any

func CreateToAddress

func CreateToAddress(data *types.AddressCreatePayload) *models.Address

func ErrorHandler

func ErrorHandler(ctx fiber.Ctx, err error) error

func GetSetDifference

func GetSetDifference[T any](original []T, compare []T) []T

func GetUser

func GetUser(context fiber.Ctx) uuid.UUID

func MergeMaps

func MergeMaps(maps ...map[string]interface{}) map[string]interface{}

overwriting duplicate keys, you should handle that if there is a need

func Remove

func Remove[T any](slice []T, s int) []T

func ToAddress

func ToAddress(data *types.AddressPayload) *models.Address

Types

type ApplictaionError

type ApplictaionError struct {
	Type    ApplictaionErrorType
	Message string
	Code    string
	Date    time.Time
}

@oas:schema:Error title: "Response Error" type: object properties:

code:
  type: string
  description: A slug code to indicate the type of the error.
  enum: [invalid_state_error, invalid_request_error, api_error, unknown_error]
message:
  type: string
  description: Description of the error that occurred.
  example: "first_name must be a string"
type:
  type: string
  description: A slug indicating the type of the error.
  enum: [QueryRunnerAlreadyReleasedError, TransactionAlreadyStartedError, TransactionNotStartedError, conflict, unauthorized, payment_authorization_error, duplicate_error, not_allowed, invalid_data, not_found, database_error, unexpected_state, invalid_argument, unknown_error]

func NewApplictaionError

func NewApplictaionError(typeStr ApplictaionErrorType, message string, params ...interface{}) *ApplictaionError

func ParseToUUID

func ParseToUUID(input interface{}) (uuid.UUID, *ApplictaionError)

func ParseUUID

func ParseUUID(str string) (uuid.UUID, *ApplictaionError)

func ParseUUIDs

func ParseUUIDs(str []string) (uuid.UUIDs, *ApplictaionError)

func (*ApplictaionError) Error

func (e *ApplictaionError) Error() string

type ApplictaionErrorType

type ApplictaionErrorType string
const (
	DB_ERROR                        ApplictaionErrorType = "DB_ERROR"
	DUPLICATE_ERROR                 ApplictaionErrorType = "DUPLICATE_ERROR"
	INVALID_ARGUMENT                ApplictaionErrorType = "INVALID_ARGUMENT"
	INVALID_DATA                    ApplictaionErrorType = "INVALID_DATA"
	UNAUTHORIZED                    ApplictaionErrorType = "UNAUTHORIZED"
	NOT_FOUND                       ApplictaionErrorType = "NOT_FOUND"
	NOT_ALLOWED                     ApplictaionErrorType = "NOT_ALLOWED"
	UNEXPECTED_STATE                ApplictaionErrorType = "UNEXPECTED_STATE"
	CONFLICT                        ApplictaionErrorType = "CONFLICT"
	PAYMENT_AUTHORIZATION_ERROR     ApplictaionErrorType = "PAYMENT_AUTHORIZATION_ERROR"
	INSUFFICIENT_INVENTORY          ApplictaionErrorType = "INSUFFICIENT_INVENTORY"
	CART_INCOMPATIBLE_STATE         ApplictaionErrorType = "CART_INCOMPATIBLE_STATE"
	QueryRunnerAlreadyReleasedError ApplictaionErrorType = "QueryRunnerAlreadyReleasedError"
	TransactionAlreadyStartedError  ApplictaionErrorType = "TransactionAlreadyStartedError"
	TransactionNotStartedError      ApplictaionErrorType = "TransactionNotStartedError"
)

type Country

type Country struct {
	Alpha2  string
	Name    string
	Alpha3  string
	Numeric string
}

type Currency

type Currency struct {
	Symbol        string
	Name          string
	SymbolNative  string
	DecimalDigits int
	Rounding      float64
	Code          string
	NamePlural    string
}

Jump to

Keyboard shortcuts

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