A backend service code challenge using Golang.
The main idea of the task is to build an API that read the payment transaction data from files (JSON
format) and return them in the API response as JSON
format. There are two payment providers flypayA
and flypayB
.
You can find the full description for the task here.
NOTE: This my first time code in Golang so there may be a lot to improve.
The application was built using Golang so you should have it installed on your machine to be able to run it.
Or you can run it through Docker.
-
Download or clone this repository to your machine.
-
Build the Docker image:
docker build -t go-challenge .
-
Create a container from the generated image:
docker run --rm --name go-challenge -p 5000:5000 go-challenge
-
You can run the service directly using:
go run main.go
-
Unit tests can be run through:
go test -v
-
Benchmarking can be run through:
go test -bench=.
NOTE: A Postman Collection for the API endpoints can be found here.
How can we add a new payment provider like flypayC
with a new schema?
-
Add
flypayC.json
file to the data directory. -
Add new Model for
flypayC.go
in the models directory:FlypayCTransactions
struct that implements theTransactions
interface.FlypayCTransaction
struct that implements theTransaction
interface.FlypayCStatusCodeMapping
map that maps thestatusCode
for theflypayC.json
schema.
-
In the
data.go
file, add the following lines in theLoadAllTransactions
function:var flyCTransactions = models.Transactions.Load(models.FlypayCTransactions{})
- Append
flyCTransactions
to thetransactions
slice as follows:transactions.append(transactions, flyCTransactions...)
.
Using Decoder
to read a JSON
file as input stream to reduce the huge spike in memory usage in reading large files.
Problem: Reading JSON
files with a non top-level array like flypayA.json and flypayB.json.
This software is licensed under the MIT License.