Rhymond/go-money

Change getDefault behaviour

caiomeemo opened this issue · 2 comments

Hi, would it be possible (and make sense of course) the money.New function to return an error if the provided currency code is not in the currencies list (e.g., "XYZ") instead of just creating it with default values? Less important and debatable, would making the default configurable (as more of a fallback) an interesting feature (e.g., set default as USD for example)?

I think the less error prone solution is to report error if currency does not exists.

The current New should be renamed "MustNew" and panic in case of invalid currency.

A new New signature should be:

func New(amount int, code string) (*Money, error)

This is a breaking change.

An additional thinking is to handle the currency coed as case insensitive, so "USD" will be the same as "usd" or "uSd"