Code Monkey home page Code Monkey logo

transaction-tracker's Introduction

Transaction Tracker

Introduction

This is a containerized Golang app that can track and save incoming requests.

Prerequisites

  • Golang 1.20 version and greater

  • PostgreSQL

  • Docker

  • Docker Compose

  • Open Api v3

  • This app includes openapi.yaml specification that you can use with Swagger Editor copy and pase the spec to this web site to see all available endpoints and methods.

Getting Started

NOTE! I strongly recommend you to run this app on MacBooks with M1, M2 etc. processor. Command for building and running application on other platform are not tested but they are defined in the project. If you will be able to run under other platform with some fixes I'm ready to REVIEW PULL REQUESTS.

For more details see corresponding titles for each command and step

Build the project in one command

This command builds both the tracker and cancel-transaction-worker services for the specified platform linux/amd64 and tag latest. It first runs the install, generate, test, buildx, and buildxworker commands.

make buildprojectx

Stage by stage commands

  1. Installing dependencies
  2. Generating models from openapi.yaml
  3. Testing the app
  4. Building the app
    • Main service
    • Worker app
  5. Running the App
  6. Stopping the App

Installing dependencies

make install

Generating models from openapi.yaml

  • First, run the following command to generate any necessary files:
make generate

Testing the App

This command runs the go test command

make test

Building the app

  • We need to build 2 docker images to run it with docker-compose
  1. Main service
  2. Worker app

Main service

  • for main tracker application which serves HTTP requests
  • to make a request to service you can use openapi.yaml specification
  • first create an account with specified balance
  • then create a transactions with specified account id from 1st stage
make buildx

Worker app

  • Post-processing worker
  • every N minutes 10 latest odd records must be canceled and balance should be corrected by the application.
  • by default N is set to 1 minute
  • to set minutes go to cmd/cancel-transaction-worker/main.go where s.Every($minutes).Minute() $minutes to N
make buildxworker

Running the App

  • To launch, we need to run docker-compose, this will launch PostgreSQL database and apply migrations to start sending requests
make composeupx

Stopping the App

  • To stop, we need to run docker-compose, this will stop application and database
make composedownx

Building the App

To build the app, run:

  • For MacOS under M1, M2 processors (tested on MacBook Air M2)
make buildx

This will build a Docker image tagged tracker:latest based on the Dockerfile at docker/macos/arm64/Dockerfile.

  • For other platforms (not tested due to lack of other platforms on hand)
make build

This will build a Docker image tagged tracker:latest based on the Dockerfile at docker/other/Dockerfile.

Building the Worker

To build the worker, run:

  • For MacOS under M1, M2 processors (tested on MacBook Air M2)
make buildxworker

This will build a Docker image tagged tracker:latest based on the Dockerfile at docker/macos/arm64/Dockerfile.

  • For other platforms (not tested due to lack of other platforms on hand)
make buildworker

This will build a Docker image tagged tracker:latest based on the Dockerfile at docker/other/Dockerfile.

Running the App without Database (see bellow to run with docker-compose that includes all dependencies)

To run the app, run:

Similar to previews commands

  • For other platforms
make run
  • For MacOS under M1, M2 processors (tested on MacBook Air M2)
make runx

This will start a Docker container running the tracker:latest image, which listens on port 8080.

Using Docker Compose

If you have Docker Compose installed, you can use it to start the app and its dependencies using the following commands:

Similar to previews commands

  • For other platforms
make composeup
  • For MacOS under M1, M2 processors (tested on MacBook Air M2)
make composeupx

This will start the app and a PostgreSQL database container.

To stop the app and the database and application, run:

Similar to previews commands

  • For other platforms
make composedown
  • For MacOS under M1, M2 processors (tested on MacBook Air M2)
make composedownx

Conclusion

That's it! You now have a containerized Golang app that can track and save incoming requests.

transaction-tracker's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.