This is a payment switch API built with GO and the Gin web framework. The API allows customers to earn points for purchases, and redeem those points for rewards.
- GO (version 1.18 or higher)
- PostgreSQL
Note lipa uses GORM as its ORM
The API has put in place the following features:
- Built on top of Gin
- Uses the supported database without writing any extra configuration files
- Reading Environment variables using godotenv
- Caching responses
- Logging
- Follows CORS policy
- DB Migration Support
- Comprehensive Error Handling in API Services
- Basic auth
- Password hashing with
bcrypt
- Simple firewall (whitelist/blacklist IP)
- Webhook Integration for Real-time Deployment Status Notifications
- Request data validation
- Email verification (sending verification email)
- Forgot password recovery
- Render
HTML
templates - Forward error logs and crash reports.
- User logout (Send an expired cookie to user’s browser or client which invalidates the user’s ‘session’)
The project follows the following directory structure:
.
├── controllers
│ ├── admin
│ │ ├── admin-auth.go
│ │ └── admin-endpoints.go
│ ├── get-products.go
│ ├── googleauth.go
│ ├── pass-reset-controller.go
│ ├── points.go
│ ├── transactions-history.go
│ └── user-auth.go
├── db
│ ├── migrations
│ │ ├── 000001_init_schema.down.sql
│ │ └── 000001_init_schema.up.sql
├── docs
│ ├── admins
│ │ └── admins.apib
│ ├── auth.apib
│ ├── index.apib
│ ├── index.html
│ ├── points.apib
│ ├── products.apib
│ ├── reset-password.apib
│ └── transaction-history.apib
├── middlewares
│ └── caching.go
│ ├── logger.go
│ └── middlewares.go
├── migrate
│ └── migrate.go
├── models
│ ├── admins.go
│ ├── products.go
│ ├── setup.go
│ ├── transactions.go
│ └── user.go
├── templates
│ ├── base.html
│ ├── passwordReset.html
│ ├── styles.html
│ ├── templates.html
│ └── verificationCode.html
├── utils
│ ├── mail
│ │ ├── email.go
│ │ └── encode.go
│ ├── token
│ │ └── token.go
│ ├── googleOAuth.go
│ └── utils.go
├── .gitignore
├── Dockerfile
├── LICENSE
├── Makefile
├── README.md
├── docker-compose.yml
├── env.sample
├── go.mod
├── go.sum
└── main.go
Follow the steps below to set up the development environment for the Loyalty Program API:
- Clone the Loyalty Program API repository from the version control system of your choice (e.g., GitHub).
git clone https://github.com/AllanM007/lipa
cd lipa
- Copy the example environment file and update the configuration variables as needed.
cp .env.example .env
-
Open the .env file in a text editor and provide the necessary values for the environment variables. Make sure to set the database connection details, JWT secret, and any other required variables.
-
Start the API and its dependencies using Docker Compose.
docker-compose up
Docker Compose will build and start the Loyalty Program API, along with the required database and any other defined services. The API will be accessible at http://localhost:8000.
- Make changes to the API code as needed. The API server will automatically reload whenever code changes are detected, allowing for a seamless development experience.
-
- Install dependencies
$ go get . || go mod || make install
- Build application
$ go build -o lipa || make build
- Start application server in development
$ go run main.go | make start
-
- Start postgres container:
$ make postgres
- Create simple_bank database:
$ make createdb
- Create a new db migration:
$ make create-migrations
- Run db migration up all versions:
$ make migrateup
- Run db migration down all versions:
$ make migratedown
- Build container
$ docker-compose build | make dcb
- Run container
$ docker-compose up -d --build | make dcu
- Stop container
$ docker-compose down | make dcd
Users have the following routes available for their authentication:
Path | Method | Required JSON | Header | Description |
---|---|---|---|---|
/api/auth/register | POST | username, firstname, lastname, gender, email, password, city, phone_number | Create User account and send activation email | |
/api/auth/verify-email/{secret_code} | GET | Verify email of correspondent account and grant login access | ||
/api/auth/login | POST | email, password | Validate logging in of user | |
/api/auth/logout | GET | Authorizaiton: "Bearer token" | Invalidate the user’s ‘session’. |
The documentation for this project is generated using aglio, an API Blueprint renderer that supports multiple themes and outputs static HTML that can be served by any web host.
To generate the documentation for this project, follow these steps:
-
Install Aglio by running
npm install -g aglio
in your terminal. -
Once installed, navigate to the root of the project and run the command
aglio -i docs/index.apib -o docs/index.html
. -
This will generate the API documentation in the
docs
folder. -
Open the
docs/index.html
file in your web browser to view the documentation.
If you make changes to the API documentation, you'll need to regenerate the docs by following the steps above.
This project is licensed under the MIT License. See the LICENSE file for details.