The converter is a data-agnostic currency conversion library that allows you to perform conversions based on a given currency and price value pair.
This library is based on GO. So before using it, make sure you have it installed in your machine.
Once you have done this, you will be able to pull this library in by typing the following command in your terminal within your go application or library.
First, you need to ope you terminal and cd into your project directory, like so:
cd $HOME/your-project-rote-folder
After doing so, you would be able to type the following command to get this library installed. For instance,
go get github.com/voyago/converter
Note: Make sure you have properly configured you go project.
The converter is a driver-based library that abstracts away its data supply implementation using different adapters. Therefore, you will not need to depend on a specific resource to retrieve given currencies' exchange rate.
We currently ship with only one data adapter, but we intend to add more as we need it. So, please, do feel free to open a PR/Issue with a choice of your preference for us to discuss/geek about it.
Creating your own driver is easy since you only need to fulfill the given store handler interface.
You will be able to see a full example by inspecting the currency layer handler. Also, if you are feeling curious, you can see how the store is able to resolve drivers based on an incoming request.
Moreover, this library ships with two different Currency Layer implementations since we had to mock handlers detail at the unit testing level.
The environment is controlled by the env package shipped within this library. It will allow you to choose what driver you would like to use when working in any given environment (staging, local, production, etc.)
It will also require you to specify your consumer app root folder name in order for it to resolve your env file path. See example
Models represent the abstraction between the converter and the real world.
The converter utilizes the currency and currencies collection information to perform the required operations to find conversion rates between currencies.
- Currency: It holds the currencies body information.
- Currencies: It is a currency collection used to store information about all our supported currencies. It also serves as the main converter entry point to resolve currencies rate.
- Price: It serves as a conversion blueprint storing all the required information used to perform a given conversion operation
The converter is the main package shipped by this library. It is in charge of performing conversion operations for a given price and destination currency.
This functionality is given in two different ways, based on a given abstract store or as a standalone function.
The store is a fetching mechanism that is able to find currencies exchange rates for any available driver through a unified interface. See example
This standalone function allows you to perform currencies conversions bypassing the store implementation. Thus, you are given all the necessary freedom to build the conversion request. See example
We work with a predefined currencies blueprint that allows us to map given exchanges rates on demand. These rates are the ones used by our converter to perform operations.
Please, feel free to fork this repository to contribute to it by submitting a functionalities/bugs-fixes pull request to enhance it.
Please see License File for more information.
There are many ways you would be able to support my open source work. There is not a right one to choose, so the choice is yours.
Nevertheless 😀, I would propose the following
- ⬆️ Follow me on Twitter.
- ⭐ Star the repository.
- 🤝 Open a pull request to fix/improve the codebase.
- ✍️ Open a pull request to improve the documentation.
- ☕ Buy me a coffee?
Thank you for reading this far. 😊