Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change getDefault behaviour #69

Open
caiomeemo opened this issue Jul 8, 2020 · 2 comments
Open

Change getDefault behaviour #69

caiomeemo opened this issue Jul 8, 2020 · 2 comments

Comments

@caiomeemo
Copy link

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)?

@totemcaf
Copy link
Contributor

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.

@totemcaf
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants