Skip to content

Rest API in Golang with JWT, PostgreSQL, GORM and Fiber.

Notifications You must be signed in to change notification settings

anshjamwal15/gopher-rest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Authorization+Authentication service in Golang

Created this project for HousewareHQ-github-octernship. My design decision was pretty simple as I created golang project for the first time. In the beginning I was pretty confused while thinking about folder structure for this project. So I just tried my best. Thanks. Ps :- Sorry for the Github Flow avoidation, was working on local-repo and commited the whole project on last day in this repo.

The kit provides the following features right out of the box:

  • User Login
  • Admin User adds a new User account(by providing the username & password)
  • Admin User deletes an existing User account from their organization
  • List all Users in their organization

Used Technologies

  • Go Fiber.
  • GORM.
  • PostgreSQL.

Folder Structure

Installation

1. Create Database and tables.

su -u postgres psql

CREATE DATABASE test

Now execute code from sql files in platforms/migrations in psql shell.

2. Install packages

go mod download

3. Install make.

sudo apt install make -y

4. Run build with test cases.

make build

5. Run binary.

make run

Getting Started

At this time, you have a RESTful API server running at http://127.0.0.1:8080. It provides the following endpoints:

  • POST /api/v1/user: Register a user in database.
  • POST /api/v1/login: authenticates a user and generates a JWT.
  • GET /api/v1/view/:userid: view user
  • GET /api/v1/all/:userid: get all user list in org.
  • POST /api/v1/create: creates new org.
  • POST /api/v1/add: creates new user.
  • DELETE /api/v1/delete/:userid/:orgid: delete user.

Test

Test APIs with Swagger.

  • GET /swagger/: get all user list in org.

Database design

Organizations

| id            | name          | created_by | created_at | updated_at |
| ------------- |:-------------:| ----------:|-----------:|-----------:|

Users

| id            | username      | password   | created_at | updated_at | role |
| ------------- |:-------------:| ----------:|-----------:|-----------:|-----:|

Org_users

| organization_id | user_id |
| ----------------|:-------:|