lightweight-bank

module
v0.0.0-...-b1d2da9 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: MIT

README

Lightweight Bank API

Lightweight Bank API is a simple banking application built with Go. It provides basic functionalities such as user registration, login, and money transfer between accounts.

Table of Contents

Installation

  1. Clone the repository:

    git clone https://github.com/barisaskaleli/lightweight-bank.git
    cd lightweight-bank
    
  2. Install dependencies:

    go mod tidy
    
  3. Set up the environment variables: Copy the .env.example file to .env and adjust the values as needed.

    cp .env.example .env
    

Configuration

The application uses environment variables for configuration. Below is a list of the variables you need to set in the .env file:

  • SERVER_PORT: The port on which the server will run.
  • JWT_SECRET: Secret key for JWT token generation.
  • DB_HOST: Database host.
  • DB_PORT: Database port.
  • DB_USER: Database user.
  • DB_PASSWORD: Database password.
  • DB_DATABASE: Database name.
  • TRANSFER_FEE: Fee for money transfers.
  • TRANSFER_FEE_ENABLED: Enable or disable transfer fee.
  • SMS_INFO_ENABLED: Enable or disable SMS notifications.

Usage

  1. Run the application via docker:

    docker compose up -d --build
    
  2. Or run by the golang:

    go run cmd/server.go
    
  3. The server will start on the port specified in the .env file.

API Endpoints

Swagger documentation is available at

http://localhost:3000/swagger/index.html
User Registration
  • URL: /register
  • Method: POST
  • Request Body:
    {
        "name": "John",
        "surname": "Doe",
        "email": "john.doe@example.com",
        "password": "password123"
    }
    
  • Response:
    {
        "id": 1,
        "account_number": "1234567890",
        "name": "John",
        "surname": "Doe",
        "email": "john.doe@example.com",
        "balance": 0.0
    }
    
User Login
  • URL: /login
  • Method: POST
  • Request Body:
    {
        "email": "john.doe@example.com",
        "password": "password123"
    }
    
  • Response:
    {
        "token": "jwt_token_here"
    }
    
Money Transfer
  • URL: /transfer
  • Method: POST
  • Request Body:
    {
        "sender_account_number": "1234567890",
        "receiver_account_number": "0987654321",
        "amount": 100.0
    }
    
  • Response:
    {
        "status": true,
        "message": "Transfer successful",
        "sender_balance": 900.0,
        "receiver_balance": 1100.0,
        "fee": 10.0
    }
    

License

This project is licensed under the MIT License.

Directories

Path Synopsis
mocks
Package mock_config is a generated GoMock package.
Package mock_config is a generated GoMock package.
Package docs Code generated by swaggo/swag.
Package docs Code generated by swaggo/swag.
internal
repository/mocks
Package mock_repository is a generated GoMock package.
Package mock_repository is a generated GoMock package.
util/mocks
Package mock_util is a generated GoMock package.
Package mock_util is a generated GoMock package.

Jump to

Keyboard shortcuts

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