pbmoney

package module
v0.0.0-...-580e6be Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2021 License: Apache-2.0 Imports: 2 Imported by: 0

README

go-pbmoney

This Go package contains utilities and arithmetic functions to work with Google’s money.proto.

These utilities can be used to check validity and sign of the Money amount, as well as arithmetic operations like adding two Money messages.

See GoDoc for package documentation.

go get -u github.com/google/go-pbmoney

See LICENSE for licensing information and CONTRIBUTING.md for contribution guidelines.

This is not an official Google project.

Documentation

Overview

Package pbmoney has utilities relating to Google's money.proto.

money.proto can be found at https://github.com/googleapis/googleapis/blob/master/google/type/money.proto, and the Go package for it is at https://godoc.org/google.golang.org/genproto/googleapis/type/Money.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidValue is returned if the specified money amount is not valid.
	ErrInvalidValue = errors.New("one of the specified money values is invalid")

	// ErrMismatchingCurrency is returned if two values don't have the same currency code.
	ErrMismatchingCurrency = errors.New("mismatching currency codes")
)

Functions

func AreEquals

func AreEquals(l, r pb.Money) bool

AreEquals returns true if values l and r are the equal, including the currency. This does not check validity of the provided values.

func AreSameCurrency

func AreSameCurrency(l, r pb.Money) bool

AreSameCurrency returns true if values l and r have a currency code and they are the same values.

func IsNegative

func IsNegative(m pb.Money) bool

IsNegative returns true if the specified money value is valid and is negative.

func IsPositive

func IsPositive(m pb.Money) bool

IsPositive returns true if the specified money value is valid and is positive.

func IsValid

func IsValid(m pb.Money) bool

IsValid checks if specified value has a valid units/nanos signs and ranges.

func IsZero

func IsZero(m pb.Money) bool

IsZero returns true if the specified money value is equal to zero.

func Must

func Must(v pb.Money, err error) pb.Money

Must panics if the given error is not nil. This can be used with other functions like: "m := Must(Sum(a,b))".

func Negate

func Negate(m pb.Money) pb.Money

Negate returns the same amount with the sign negated.

func Sum

func Sum(l, r pb.Money) (pb.Money, error)

Sum adds two values. Returns an error if one of the values are invalid or currency codes are not matching (unless currency code is unspecified for both).

Types

This section is empty.

Jump to

Keyboard shortcuts

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