internal

package
v0.0.0-...-3978a51 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrZeroBalance = errors.New("account balance is zero")

Functions

func NewErrorf

func NewErrorf(code ErrorCode, format string, a ...any) error

NewErrorf instantiates a new error.

func WrapErrorf

func WrapErrorf(orig error, code ErrorCode, format string, a ...any) error

WrapErrorf returns a wrapped error.

Types

type Account

type Account struct {
	ID        int64     `json:"id"`
	UserID    int64     `json:"-"`
	Balance   USD       `json:"balance"`
	CreatedAt time.Time `json:"-"`
}

type BalanceUpdateRequest

type BalanceUpdateRequest struct {
	Amount USD `json:"amount"`
}

func NewBalanceUpdateRequest

func NewBalanceUpdateRequest(amount USD) BalanceUpdateRequest

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error represents an error that could be wrapping another error, it includes a code for determining what triggered the error.

func (*Error) Code

func (e *Error) Code() ErrorCode

Code returns the code representing this error.

func (*Error) Error

func (e *Error) Error() string

Error returns the message, when wrapping errors the wrapped error is returned.

func (*Error) Message

func (e *Error) Message() string

Message returns the custom message of the error.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the wrapped error, if any.

type ErrorCode

type ErrorCode uint

ErrorCode defines supported error codes.

const (
	ErrorCodeUnknown ErrorCode = iota
	ErrorCodeNotFound
	ErrorCodeInvalidArgument
	ErrorCodeDuplicate
	ErrorCodeUnauthorized
)

type USD

type USD int64

USD represents US dollar amount in terms of cents

func ToUSD

func ToUSD(f float64) USD

ToUSD converts a float64 to USD e.g. 1.23 to $1.23, 1.345 to $1.35

func (USD) Float64

func (m USD) Float64() float64

Float64 converts a USD to float64

func (USD) Multiply

func (m USD) Multiply(f float64) USD

Multiply safely multiplies a USD value by a float64, rounding to the nearest cent.

func (USD) String

func (m USD) String() string

String returns a formatted USD value

type User

type User struct {
	ID        int64     `json:"id"`
	FirstName string    `json:"firstName"`
	LastName  string    `json:"lastName"`
	Email     string    `json:"email"`
	Password  string    `json:"-"`
	CreatedAt time.Time `json:"createdAt,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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