Simple Shopping Cart written in Golang.
go get github.com/nmeji/shoppingcart
After go-getting, the binary build $GOBIN/shoppingcart
should already be present.
Run it in the same folder with product-catalog.json
You may edit product-catalog.json to reflect changes to available products
At first, I thought of implementing the rules in something like pricing-rules.json. But due to the extra overhead I opted to write it in rules.go instead.
You can either run the commands in $GOPATH/src/github.com/nmeji/shoppingcart or you may also copy the product-catalog.json file from that folder and put it in some other directory. The important thing is to make sure that $GOBIN variable is already set. If it is not yet set, I think it is set by default to $GOPATH/bin directory.
- Run
shoppingcart
(This will search for product-catalog.json in the same folder) - You may type
help
to list all available commands - Just to provide you with some commands right away, here's a list of the important commands to remember:
- Type
catalog
to show the different products and their prices. - In order to add items to cart, the usage is
add <id> [quantity]
- Use
cart
to show cart summary which provides you the total price and the total items you can expect to get after purchasing. - If you wish to apply a promo code, type
promo <code>
(eg. promo I<3AMAYSIM)
2 tests: amaysim/cart_test.go and amaysim/rules_test.go. In order to run both tests, run go test -coverprofile=testprofile ./amaysim/