DEV Community

Booranasak Kanthong
Booranasak Kanthong

Posted on

Building, Securing, and Deploying a Go App with GitLab CI/CD: README.md

# Bank API

A simple in-memory bank account API built in Go.

- **Server listens on**: `:8008`  
- **Base URL**: `http://localhost:8008`

---

## Table of Contents

1. [Endpoints](#endpoints)  
2. [Mock Data](#mock-data)  
3. [Getting Started](#getting-started)  
4. [Running the Server](#running-the-server)  
5. [Running Tests & Coverage](#running-tests--coverage)  

---

## Endpoints

### 1. Welcome Root

- **Path**: `/`  
- **Method**: `GET`  
- **Description**: Returns a friendly welcome message.

```

bash
curl http://localhost:8008/


Enter fullscreen mode Exit fullscreen mode

2. List All Accounts

  • Path: /accounts
  • Method: GET
  • Description: Returns a JSON array of all accounts (ID, Name, Balance).

bash
curl http://localhost:8008/accounts


Enter fullscreen mode Exit fullscreen mode

3. Create a New Account

  • Path: /accounts
  • Method: POST
  • Description: Opens a new account with zero (or seeded) balance.
  • Body: JSON with a Name field.

bash
curl -X POST http://localhost:8008/accounts \
     -H "Content-Type: application/json" \
     -d '{"Name":"Zara"}'


Enter fullscreen mode Exit fullscreen mode

4. Get Single Account

  • Path: /accounts/{id}
  • Method: GET
  • Description: Fetches the account with the given id.

bash
curl http://localhost:8008/accounts/1


Enter fullscreen mode Exit fullscreen mode

5. Deposit into Account

  • Path: /accounts/{id}/deposit
  • Method: POST
  • Description: Adds funds to the specified account.
  • Body: JSON with an Amount field (must be > 0).

bash
curl -X POST http://localhost:8008/accounts/1/deposit \
     -H "Content-Type: application/json" \
     -d '{"Amount":100}'


Enter fullscreen mode Exit fullscreen mode

6. Withdraw from Account

  • Path: /accounts/{id}/withdraw
  • Method: POST
  • Description: Subtracts funds from the specified account (must have sufficient balance).
  • Body: JSON with an Amount field (must be > 0 and ≤ current balance).

bash
curl -X POST http://localhost:8008/accounts/1/withdraw \
     -H "Content-Type: application/json" \
     -d '{"Amount":50}'


Enter fullscreen mode Exit fullscreen mode

Mock Data

On startup, the in-memory store is seeded with 10 mock accounts:

ID Name Balance
1 Alice 1000
2 Bob 2000
3 Carol 3000
4 Dave 4000
5 Eve 5000
6 Frank 6000
7 Grace 7000
8 Heidi 8000
9 Ivan 9000
10 Judy 10000

Getting Started

  1. Clone the repository and cd into it:

bash
   git clone <repo-url>
   cd bank-api


Enter fullscreen mode Exit fullscreen mode
  1. Build (optional):

bash
   go build ./cmd/server


Enter fullscreen mode Exit fullscreen mode

Running the Server

Start the HTTP server on port 8008:


bash
go run ./cmd/server/main.go


Enter fullscreen mode Exit fullscreen mode

Visit http://localhost:8008/ in your browser or use the curl commands above.


Running Tests & Coverage

Run all tests verbosely and display coverage:


bash
go test -v -cover ./...


Enter fullscreen mode Exit fullscreen mode

License

MIT © Booranasak Kanthong

Top comments (0)