A lightweight and native RESTful Todo API built using Go's standard net/http
library and PostgreSQL.
This project is ideal for learning how to build REST APIs in Go without external routing frameworks.
- 📋 CRUD operations for Todo items
- ⚡ Native
net/http
routing - 🗄 PostgreSQL integration with UUID primary keys
- 🧪 Swagger documentation (
swaggo
) - 🛠 Auto-creation of the
todos
table on startup - 🔒 Secure ID generation via
pgcrypto
- Go 1.24+
- PostgreSQL
- swag CLI (for generating Swagger docs)
git clone https://github.com/your-username/go-native-rest-todo.git
cd go-native-rest-todo
CREATE DATABASE tododb;
go run .
Server will be available at:
- 🌐 http://localhost:8080
- 📚 Swagger UI: http://localhost:8080/swagger/index.html
Method | Endpoint | Description |
---|---|---|
GET | /todos |
Get all todos |
POST | /todos |
Create a new todo |
PUT | /todos/rename/{id} |
Rename a todo |
PUT | /todos/done/{id} |
Update a todo done state |
DELETE | /todos/{id} |
Delete a todo |
All endpoints are documented in Swagger.
Make sure you have swag installed:
go install github.com/swaggo/swag/cmd/swag@latest
Then generate the docs:
swag init
For working with the application, you need to set the following environment variables:
DB_HOST
: The hostname or IP address of your PostgreSQL server.DB_PORT
: The port number of your PostgreSQL server.DB_USER
: The username for your PostgreSQL database.DB_PASSWORD
: The password for your PostgreSQL database.DB_NAME
: The name of your PostgreSQL database.
. ├── main.go # Entry point ├── db.go # DB initialization and table creation ├── todo.go # Todo handlers and models ├── handlers.go # Todo handlers and models ├── models.go # Todo models ├── docs/ # Swagger generated docs └── go.mod
MIT License