A production-ready, modular REST API built with Go, PostgreSQL, and JWT authentication.
- ✅ Clean architecture (handler → service → repository)
- 🔐 JWT-based authentication (register, login, protect routes)
- 🗃️ PostgreSQL persistence
- 📦 CRUD operations on tasks
- 🔍 Pagination, filtering, and sorting
- 🧼 Input validation using
go-playground/validator
- 🧱 Structured error handling
- 📁 Environment-based config loading
gotask/
├── cmd/
│ └── server/ # app entrypoint
├── internal/
│ ├── auth/ # register, login, jwt
│ └── task/ # task logic
├── pkg/
│ ├── config/ # env loader
│ ├── db/ # database connection
│ ├── response/ # response writers
│ └── validation/ # form validation
└── .env # local secrets (not committed)
- Go 1.21+
- PostgreSQL
- Docker (optional)
git clone https://github.com/sudarshanmg/gotask.git
cd gotask
PORT=8080
URL=postgres://<user>:<password>@localhost:5432/gotaskdb?sslmode=disable
JWT_SECRET=yourSuperSecretKey
JWT_EXPIRY=15m
docker run -d --name pg \
-p 5432:5432 \
-e POSTGRES_USER=su \
-e POSTGRES_PASSWORD=secret \
-e POSTGRES_DB=gotaskdb \
postgres
-- run in psql
CREATE TABLE users (
id SERIAL PRIMARY KEY,
username TEXT UNIQUE NOT NULL,
password_hash TEXT NOT NULL,
created_at TIMESTAMP DEFAULT NOW()
);
CREATE TABLE tasks (
id SERIAL PRIMARY KEY,
title TEXT NOT NULL,
description TEXT,
completed BOOLEAN DEFAULT false,
created_at TIMESTAMP DEFAULT NOW(),
updated_at TIMESTAMP DEFAULT NOW()
);
go run cmd/server/main.go
POST /auth/register
– Register userPOST /auth/login
– Login, returns JWT token
GET /tasks
– List tasks (supports?page=1&limit=10&sort=created_at&order=desc
)POST /tasks
– Create a taskGET /tasks/{id}
– Get task by IDPUT /tasks/{id}
– Update taskDELETE /tasks/{id}
– Delete task
💡 Pass
Authorization: Bearer <token>
in headers for protected routes.
- JWT auth
- Filtering & pagination
- Swagger docs
- Dockerfile & Compose setup
- Unit & integration tests
- CI/CD via GitHub Actions
Made with ❤️ by @sudarshanmg