A Go project with some API which retrieves/modifies some files containing the balance of accounts. The project should include a config file, which stores the directory of these files.
- An API to create a number of accounts (balance files) in the directory
- The balance of each account should be generated randomly, ranging from 1,000 to 100,000
- These files (accounts' balances) could be created only once
- An API to get the balance of one/all account(s)
- An API to add number x to the balance of one/all account(s)
- Specify the pieces of code which have applied SOLID principle
- Comment
- Search for #SOLID to see the examples of applied SOLID principles
- Search for #TODO to see the possible improvements which I could not implement in the specified time period
- Search for #Desc to see my reasons for making some specific decisions
from the highest level to lowest:
- API layer (./api)
- The business layer (./account)
- The internal layer (./internal)
- Create accounts URL:
localhost:8080/accounts?number=1000
Verb:POST
- Get a balance URL:
localhost:8080/accounts?id=12
Verb:GET
- Get sum of all balances URL:
localhost:8080/accounts?result=aggregate
Verb:GET
- increase a balance URL:
localhost:8080/accounts?id=12&increase=1000
Verb:PUT
- increase all balances URL:
localhost:8080/accounts?increase=1000
Verb:PUT
- accountsDir: string, the directory which keeps the accounts files
- logsFile: string, the file path to store logs
- isConcurrent: boolean, to check if the service should behave concurrently
- isProduction: boolean, production vs debug (excluded from config_test)
- restPort: number, rest api port
- defaultAccountNumbers: number, the default number of accounts to created
- randomBalanceMinRange: number, the min range of random balance generation
- randomBalanceMaxRange: number, the max range of random balance generation
- maxConcurrentGoroutines: number, the max number of concurrent go routines
- accountFileExtension: text, the file extension of accounts including a dot (.txt)
- Add more tests
- Implement delete API
- Define more explicit error types
- assert them in tests
- use them to return more explicit HTTP error codes
- return error in get/update methods when there is no balance file
- Rollback changes when batch update is failed
- Wrap zap(logger) by an interface
- Put data validation on config (random balance generation range for instance)