An open API service indexing awesome lists of open source software.

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

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)