price

package
v0.0.5-0...-8e55a6f Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var File_price_price_proto protoreflect.FileDescriptor

Functions

This section is empty.

Types

type Price

type Price struct {
	//Amount minor units (e.g. cents). for some database(like sqlite), decimal is stored as float, it may cause problems when calculating
	Amount       int64 `json:"amount"`
	CurrencyCode string
}

Price database friendly price struct

func MustNew

func MustNew(n, currencyCode string) Price

func MustNewFromInt64

func MustNewFromInt64(n int64, currencyCode string) Price

func NewPrice

func NewPrice(n, currencyCode string) (p Price, err error)

func NewPriceFromCurrency

func NewPriceFromCurrency(a currency.Amount) (Price, error)

NewPriceFromCurrency convert currency.Amount into database friendly Price

func NewPriceFromInt64

func NewPriceFromInt64(n int64, currencyCode string) (p Price, err error)

func NewPriceFromPb

func NewPriceFromPb(a *PricePb) (Price, error)

func (Price) IsEmpty

func (p Price) IsEmpty() bool

func (Price) ToCurrency

func (p Price) ToCurrency() currency.Amount

func (Price) ToPricePb

func (p Price) ToPricePb(ctx context.Context) *PricePb

type PricePb

type PricePb struct {
	Amount        int64  `protobuf:"varint,1,opt,name=amount,proto3" json:"amount,omitempty"`
	CurrencyCode  string `protobuf:"bytes,2,opt,name=currency_code,json=currencyCode,proto3" json:"currency_code,omitempty"`
	Digits        int32  `protobuf:"varint,3,opt,name=digits,proto3" json:"digits,omitempty"`
	Text          string `protobuf:"bytes,4,opt,name=text,proto3" json:"text,omitempty"`
	AmountDecimal string `protobuf:"bytes,5,opt,name=amount_decimal,json=amountDecimal,proto3" json:"amount_decimal,omitempty"`
	// contains filtered or unexported fields
}

func (*PricePb) Descriptor deprecated

func (*PricePb) Descriptor() ([]byte, []int)

Deprecated: Use PricePb.ProtoReflect.Descriptor instead.

func (*PricePb) GetAmount

func (x *PricePb) GetAmount() int64

func (*PricePb) GetAmountDecimal

func (x *PricePb) GetAmountDecimal() string

func (*PricePb) GetCurrencyCode

func (x *PricePb) GetCurrencyCode() string

func (*PricePb) GetDigits

func (x *PricePb) GetDigits() int32

func (*PricePb) GetText

func (x *PricePb) GetText() string

func (*PricePb) ProtoMessage

func (*PricePb) ProtoMessage()

func (*PricePb) ProtoReflect

func (x *PricePb) ProtoReflect() protoreflect.Message

func (*PricePb) Reset

func (x *PricePb) Reset()

func (*PricePb) String

func (x *PricePb) String() string

func (*PricePb) Validate

func (m *PricePb) Validate() error

Validate checks the field values on PricePb with the rules defined in the proto definition for this message. If any rules are violated, the first error encountered is returned, or nil if there are no violations.

func (*PricePb) ValidateAll

func (m *PricePb) ValidateAll() error

ValidateAll checks the field values on PricePb with the rules defined in the proto definition for this message. If any rules are violated, the result is a list of violation errors wrapped in PricePbMultiError, or nil if none found.

type PricePbMultiError

type PricePbMultiError []error

PricePbMultiError is an error wrapping multiple validation errors returned by PricePb.ValidateAll() if the designated constraints aren't met.

func (PricePbMultiError) AllErrors

func (m PricePbMultiError) AllErrors() []error

AllErrors returns a list of validation violation errors.

func (PricePbMultiError) Error

func (m PricePbMultiError) Error() string

Error returns a concatenation of all the error messages it wraps.

type PricePbValidationError

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

PricePbValidationError is the validation error returned by PricePb.Validate if the designated constraints aren't met.

func (PricePbValidationError) Cause

func (e PricePbValidationError) Cause() error

Cause function returns cause value.

func (PricePbValidationError) Error

func (e PricePbValidationError) Error() string

Error satisfies the builtin error interface

func (PricePbValidationError) ErrorName

func (e PricePbValidationError) ErrorName() string

ErrorName returns error name.

func (PricePbValidationError) Field

func (e PricePbValidationError) Field() string

Field function returns field value.

func (PricePbValidationError) Key

func (e PricePbValidationError) Key() bool

Key function returns key value.

func (PricePbValidationError) Reason

func (e PricePbValidationError) Reason() string

Reason function returns reason value.

Jump to

Keyboard shortcuts

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