https://github.com/sudarshanmg/gotask
A complete backend for Task Manager with JWT Authentication, filtering, sorting and pagination support
https://github.com/sudarshanmg/gotask
api api-rest backend go golang jwt jwt-authentication postgresql
Last synced: 6 months ago
JSON representation
A complete backend for Task Manager with JWT Authentication, filtering, sorting and pagination support
- Host: GitHub
- URL: https://github.com/sudarshanmg/gotask
- Owner: sudarshanmg
- Created: 2025-05-14T20:22:39.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-16T06:58:33.000Z (about 1 year ago)
- Last Synced: 2025-08-22T19:26:34.930Z (10 months ago)
- Topics: api, api-rest, backend, go, golang, jwt, jwt-authentication, postgresql
- Language: Go
- Homepage:
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## ๐ gotask โ Secure Task Manager API in Go
A production-ready, modular REST API built with Go, PostgreSQL, and JWT authentication.
---
### โ๏ธ Features
- โ
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
---
### ๐ Project Structure
```
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)
```
---
### ๐ง Requirements
- Go 1.21+
- PostgreSQL
- Docker (optional)
---
### ๐ Getting Started
#### 1. Clone the repo
```bash
git clone https://github.com/sudarshanmg/gotask.git
cd gotask
```
#### 2. Create `.env`
```env
PORT=8080
URL=postgres://:@localhost:5432/gotaskdb?sslmode=disable
JWT_SECRET=yourSuperSecretKey
JWT_EXPIRY=15m
```
#### 3. Run Postgres (Docker optional)
```bash
docker run -d --name pg \
-p 5432:5432 \
-e POSTGRES_USER=su \
-e POSTGRES_PASSWORD=secret \
-e POSTGRES_DB=gotaskdb \
postgres
```
#### 4. Create tables
```sql
-- 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()
);
```
#### 5. Run the server
```bash
go run cmd/server/main.go
```
---
### ๐งช API Endpoints
#### ๐ Auth
- `POST /auth/register` โ Register user
- `POST /auth/login` โ Login, returns JWT token
#### ๐ Tasks (requires JWT)
- `GET /tasks` โ List tasks (supports `?page=1&limit=10&sort=created_at&order=desc`)
- `POST /tasks` โ Create a task
- `GET /tasks/{id}` โ Get task by ID
- `PUT /tasks/{id}` โ Update task
- `DELETE /tasks/{id}` โ Delete task
> ๐ก Pass `Authorization: Bearer ` in headers for protected routes.
---
### ๐งญ Roadmap
- [x] JWT auth
- [x] Filtering & pagination
- [ ] Swagger docs
- [ ] Dockerfile & Compose setup
- [ ] Unit & integration tests
- [ ] CI/CD via GitHub Actions
---
### ๐จโ๐ป Author
Made with โค๏ธ by [@sudarshanmg](https://github.com/sudarshanmg)