Pricing Engine
How to Execute
git clone https://github.com/1swaraj/pricing-engine.git
cd pricing-engine
If you have make installed on your system then :-
make build
make test
make run
Else the classic way
cd cmd
go build .
./cmd
Understanding the CodeBase
pricing-engine-go
-
constants.go :-
- Stores all the error messages
- Stores the default location for the config.yaml file
-
pricing_engine.go :-
- Stores the structs needed for the request and response
config
This directory has code that is primarily concerned with the config management like reading the configs from a yaml file and reading the data from the csv files present in the data (config/data) directory
- data :-
- This directory has config.yaml which stores the configuration details such as the date format and the data sources corresponding to base_rate, driver_age factor etc
- interface.go :-
- Defines the blueprint for the config package
- Intentionally create to make creation of test cases possible
- types.go :-
- Defines the Config struct which stores information about things like :-
- Date Format
- Data Source - Paths of all the CSV files needed for calulations
- Base,Age,LicenseLength,InsuranceGroup - used to store the hash map generated from the csv
- MaxBase, MinBase, MaxAge, MinAge etc - used to store the max / min value in the range (generated from the CSV)
- Defines the Config struct which stores information about things like :-
- utils.go :-
- Helps us with utilities like ReadFromCSV and ReadFromYAML
- config.go :-
- Implements the GetConfig and SetConfig methods defined in the interface
service
app
- find_factor.go :-
- Implements a generic method that finds the factor corresponding to the input
- i.e. GetFactor method will be able to find the age factor as well as the insurance group factor
- generate_pricing.go :-
- Implements the core logic of the application
- generate_pricing_test.go :-
- Wrote a few test cases (that depict the importance of the architectural choice of defining the IConfig interface)
- types.go :-
- Defines the App struct
rpc
Implements the rpc call mechanism (go-chi)
utils
- interface.go :-
- Defines the IDateHelper interface
- This interface will be helpful in generating mocks for testing
- Similar to what we did for IConfig interface
- utils.go :-
- Implements functions that will help us in doing date time related operations.
- Eg :- AgeFromDate,Parse etc This also helps in making the code extensible. If tomorrow, time.Time is deprecated for some reason, we just need to make the changes in this package and not in the entire codebase.