项目作者: DavyJ0nes

项目描述 :
Example of API built with Go
高级语言: Go
项目地址: git://github.com/DavyJ0nes/products.git
创建时间: 2018-07-05T15:30:55Z
项目社区:https://github.com/DavyJ0nes/products

开源协议:Apache License 2.0

下载


Products API

Go Report Card

Table of Contents

Description

Example of how to create a simple API that could be used as part of a commerce system or POS.

You can find information about the data models used here

Basic Full Transaction Example

  1. Run the docker container with: make run-docker
  2. Send a POST request to the container (this is done with curl): make transaction-test

You should see output similar to the following:
This output can be used by a receipt printer

  1. {
  2. "order_id": "f488a533-11cd-4787-b0bb-a945b5cb382c",
  3. "formatted_products": [
  4. {
  5. "product_quantity": 1,
  6. "product_name": "Coffee Mug",
  7. "price": 599
  8. },
  9. {
  10. "product_quantity": 1,
  11. "product_name": "Coaster",
  12. "price": 250
  13. },
  14. {
  15. "product_quantity": 1,
  16. "product_name": "Glass Tumbler",
  17. "price": 1299
  18. }
  19. ],
  20. "formatted_date_time": "06-07-2018 23:13:19",
  21. "subtotal": 1943,
  22. "taxtotal": 389,
  23. "tax_breakdown": [
  24. {
  25. "Name": "VAT",
  26. "Amount": 0.2,
  27. "Total": 389
  28. }
  29. ],
  30. "total": 2332
  31. }

Usage

How to build and run the API as a service. More information on these commands can be found in the Makefile

  1. # Basic run while testing
  2. make run
  3. # Run test suite over all packages
  4. make test
  5. # Build Docker Image
  6. make build
  7. # Run Docker Image
  8. make run-docker
  9. # Deploy to Kubernetes Cluster
  10. make deploy
  11. # Make POST request to test creating a new transaction
  12. make transaction-test
  13. # Make POST request to test creating a new product and then GETting it
  14. make product-test

TODO

  • mock dependency on currency converter. Causes flaky tests due to changing conversion rates
  • Abstract transaction totals to separate package and look at cleaner implementation
  • Implement Data store
  • Add authentication to API
  • Improve transactions to better handle multiple quantities of the same product
  • Tidy up test suites for improved readability
  • Improve the healthz endpoint
  • Add readyz endpoint
  • Look to move to using gRPC

License

Apache 2.0