checkout

command module
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 3 Imported by: 0

README

Checkout

Components

  • Go HTTP server exposing a RESTful API built with httprouter.
  • Multiple DB support: SQLite (in-memory and file store), Postgres (for production use)
  • Dedicated promotions engine for applying promotions/deals to purchases
  • Prometheus metrics server endpoint.

System Design

The Checkout server is a stateless web server (microservice) exposing a RESTful HTTP interface.

Code layout
.
├── main.go      // main application entrypoint
├── build        // stores generated binary and code coverage data
├── client       // HTTP client wrappers for interacting with the server REST API
├── cmd          // CLI command package (cobra/viper)
├── constants    // Contains embedded version, service name and other global constants
├── database     // Multiple database driver implementations using GORM
├── docs
│   ├── openapi  // OpenAPI/Swagger docs that can be imported into Postman
│   └── markdown // Additional documentation
├── integration  // Integration testing
├── model        // Database and API model
├── promotions   // Engine with composable promotions strategy implementations
└── server       // HTTP server built with httprouter (high performance, panic recovery, concurrency)

REST API Endpoints

1. Status
  • Endpoint: GET /status
  • Description: Returns the status of the service.
  • Response:
    {
      "message": "OK",
      "version": "1.0.0",
      "service": "checkout-svc"
    }
    

2. Health
  • Endpoint: GET /health
  • Description: Checks the health of the service and its dependencies.
  • Response:
    {
      "version": "1.0.0",
      "service": "checkout-svc",
      "failures": []
    }
    

3. Get Item Price
  • Endpoint: GET /v0/inventory/item/price/:key
  • Description: Get price information for a single item by SKU or name.
  • Parameters:
    • key (path): The SKU or name of the item.
  • Response:
    {
      "items": [
        {
          "name": "Item1",
          "sku": "SKU1",
          "price": 10.99,
          "inventory_quantity": 100
        }
      ],
      "total": 10.99,
      "total_with_discount": 10.99
    }
    

4. Get Items Price
  • Endpoint: POST /v0/inventory/items/price
  • Description: Get total price for a batch of items by SKUs.
  • Request Body:
    {
      "skus": ["SKU1", "SKU2"]
    }
    
  • Response:
    {
      "items": [
        {
          "name": "Item1",
          "sku": "SKU1",
          "price": 10.99,
          "inventory_quantity": 100
        },
        {
          "name": "Item2",
          "sku": "SKU2",
          "price": 20.99,
          "inventory_quantity": 200
        }
      ],
      "total": 31.98,
      "total_with_discount": 31.98
    }
    

5. Purchase Items
  • Endpoint: POST /v0/inventory/items/purchase
  • Description: Execute a purchase order for the supplied item list.
  • Request Body:
    {
      "skus": ["SKU1", "SKU2"]
    }
    
  • Response:
    {
      "order_reference": "ORD-12345",
      "cost": 31.98
    }
    
6. Get Orders
  • Endpoint: GET /v0/orders
  • Description: List all purchase orders.
  • Authentication: Required.
  • Response:
    [
      {
        "reference": "ORD-12345",
        "skus": ["SKU1", "SKU2"],
        "cost": 31.98
      }
    ]
    
7. Add Items
  • Endpoint: POST /v0/inventory/items
  • Description: Add new or updated items to the inventory.
  • Authentication: Required.
  • Request Body:
    {
      "items": [
        {
          "name": "Item1",
          "sku": "SKU1",
          "price": 10.99,
          "inventory_quantity": 100
        }
      ]
    }
    
  • Response:
    {
      "items": [
        {
          "id": 1,
          "name": "Item1",
          "sku": "SKU1",
          "price": 10.99,
          "inventory_quantity": 100
        }
      ]
    }
    
Authentication
  • Endpoints requiring authentication:
    • GET /v0/orders
    • POST /v0/inventory/items
  • Authentication Method: Include a valid password in the X-Auth-Password header.
Error Responses

All endpoints return the following error response in case of failure:

{
  "error": "Error message"
}

Getting started

Usage
$ make build
$ ./build/checkout --help   
checkout server command line interface.

VERSION:
  semver: v0.0.1-1-g0ab807f
  commit: 0ab807f7b986bd8cfa4b593e97b02da62bc4ba92
  compilation date: 2025-02-19 22:08:26

Usage:
  checkout [subcommand] [flags]
  checkout [command]

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  help        Help about any command
  run         Start the checkout server
  version     Print version details

Flags:
  -h, --help   help for checkout

Use "checkout [command] --help" for more information about a command.
Run the checkout server with in-memory DB
$ make run
Run with SQLite
$ make build
$ ./build/checkout run --sqlite data/db --log-level debug --password 1234
Run with connection to Postgres

Ensure that you have a Postgres instance listening on <DB_HOST>:<DB_PORT> ready to accept connection.

$ make build
$ ./build/checkout run --db-host <DB_HOST> --db-port <DB_PORT> --db-user <DB_USER> --db-password <DB_PASSWORD> --password 1234
Run package tests
$ make test

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
mock
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.
Package event defines the transport-agnostic message envelope exchanged between services.
Package event defines the transport-agnostic message envelope exchanged between services.
api
middleware
Package middleware holds HTTP middleware shared by every service that runs on the common httpserver.
Package middleware holds HTTP middleware shared by every service that runs on the common httpserver.
integration
kafka
Package kafka implements the messaging interfaces against a Kafka broker.
Package kafka implements the messaging interfaces against a Kafka broker.
mock
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.
auth
Package auth resolves a credential to a caller identity.
Package auth resolves a credential to a caller identity.
auth/mock
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.
orders
@title Checkout Orders Service API @version 1.0 @description API for managing inventory and orders @host localhost:8000 @BasePath /
@title Checkout Orders Service API @version 1.0 @description API for managing inventory and orders @host localhost:8000 @BasePath /
orders/mock
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.
worker
Package worker provides the goroutine-lifecycle boilerplate shared by every background process in the app (the orders outbox relay, the notifier consume loop).
Package worker provides the goroutine-lifecycle boilerplate shared by every background process in the app (the orders outbox relay, the notifier consume loop).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL