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:
-
POST:/api/v1/users
- registrates new user
-
POST:/api/v1/auth
- authorizes user, generates JWT token and writing it in cache
-
POST:/api/v1/auth/changePassword
- changes password with deleting valid token in Redis
valid tokens storage (requires token in Bearer header)
-
GET:/api/v1/users/:username
- get user profile by username (requires token in Bearer header)
-
GET:/api/v1/users/me
- returns current user profile (requires token in Bearer header)
-
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