Book :
Add Book (Administrator)
Get Book Info
Get All Books Info
Remove Book (Administrator)
Users :
User Signup
User Signin
Refresh JWT token pair
Admin Signup (Administrator)
Give Admin Role (Administrator)
Revoke Admin Role (Administrator) [Blacklisting JWT access token for its lifetime]
Delete any User (Administrator) [Blacklisting JWT access token for its lifetime]
Issue :
Add Issue (Administrator)
Get Issues
Delete Issue (Administrator)
Backend Framework : Go-Fiber
Database : Postresql
ORM : GORM
Password Hashing : HS256
Session Management : JWT Token
Cache : Redis
Clone the project and install required go packages
(replace .env
contents with .env.dev
)
You need postgres to be installed on the system
git clone https://github.com/sswastik02/Books-API
go mod tidy # or go mod download
Note : go mod tidy
ensures that the go.mod file matches the source code in the module, you can also go get
each library individually
go run main.go -createadmin
go run main.go -runserver
Alternatively, docker container can be built from the docker-compose.yml
file
(replace .env
contents with .env.prod
)
You will need docker and docker-compose for this
docker exec -it <go_fiber_container_name> go run main.go -createadmin
go fiber container name is the name of the container running the go fiber backend that is running on your system. You can view it by running docker ps
docker-compose up --build
Note : You need to make sure nothing is already running on the ports 8000 and 5432. If there is you need to stop them
We will add a go.mod
file with link to our repo with the command in the root directory:
go mod init github.com/sswastik02/Books-API
Created the files and folders manually, forming the following directory tree
Books-API
├── go.mod
├── main.go
├── .env
├── models/
└── storage/
Next we start writing to the main.go file for :
- Import Neccessary Go Libraries(Such as Fiber and Gorm)
- Importing .env
- Connect with Database
- Initialise Fiber Framework
- Write routes and functions
We write the book model required to store in the database in the models folder along with the migrate method
This Step includes making configuration to connect with postgresSQL
You need to create a postgres database on your localhost before writing the env file
In the following, keep in mind the < angular brackets > are to denote variables you have to set yourself. In the actual, omit the <>
The basic structure of the file looks like :
DB_HOST=localhost
DB_PORT=5432
DB_USER=<username>
DB_PASS=<password>
DB_NAME=<dbname>
DB_SSLMODE=disable
JWT_SECRET=<jwtsecret>
The above .env file is outdated as it was during the inital steps of the project. You can have a look at env.dev
or env.prod
for reference
GoLang Setup and Tutorial
Postgres Setup for Ubuntu 20.04
Playlist with GO-Fiber and PostgresQL
GORM models
Posgresql Basic create user and database
Implementing Password Authentication
Implementing JWT in Fiber
Implemeting JWT with refresh token
Dockerizing Fiber with Postgresql
Setting up Redis on Ubuntu
Overview of the GORM object relational mapper