go-gin-boilerplate

Stars
2

Golang + Gin JWT authentication template

Small REST API template written in Golang using Gin, PostgreSQL, JWT and Redis. Project: user profile CRUD with authorization, authentication and token validation


Endpoints:

  1. POST:/api/v1/users - registrates new user
  2. POST:/api/v1/auth - authorizes user, generates JWT token and writing it in cache
  3. POST:/api/v1/auth/changePassword - changes password with deleting valid token in Redis valid tokens storage (requires token in Bearer header)
  4. GET:/api/v1/users/:username - get user profile by username (requires token in Bearer header)
  5. GET:/api/v1/users/me - returns current user profile (requires token in Bearer header)
  6. PATCH:/api/v1/users/me - updates current user profile (requires token in Bearer header)

Launch guide:

  • Make sure that your .env looks like this:
DB_HOST=localhost
DB_PORT=5432
DB_PASSWORD=password
DB_USER=postgres
DB_NAME=demo
JWT_SECRET=secret
REDIS_CONNECTION=localhost:6379
  • Make sure that you running Redis and PostgreSQL on your machine
  • Run go run main.go in terminal
Related Projects