mirror of
https://github.com/ION606/MailPocket.git
synced 2026-05-14 22:06:55 +00:00
96264264556bda030a4ec8da1a54ef7b8e8c79c5
MailPocket
MailPocket is inspired by the idea of a pocket—a small, handy container designed to securely hold valuable items. In this case, it’s an extremely lightweight “pocket” for safely collecting email form submissions written in Go.
This project provides two independent server implementations:
- Batched Write Server: A dependency-free server that stores emails in a CSV file.
- SQLite Server: A server that uses SQLite for reliable and structured email storage.
Both servers are designed to be simple, efficient, and easy to deploy.
Features
-
Batched Write Server:
- No external dependencies.
- Stores emails in a CSV file (
emails.csv). - Batches writes to reduce disk I/O.
- Lightweight and minimalistic.
-
SQLite Server:
- Uses SQLite for structured and reliable email storage.
- Prevents duplicate emails with a unique constraint.
- Easy to query and manage stored emails.
- Slightly more robust and feature-rich.
Getting Started
Prerequisites
- Go 1.20 or higher.
- For the SQLite Server, the
modernc.org/sqlitedependency will be installed automatically.
Running the Servers
1.0 Clone the repository:
git clone https://github.com/your-username/forms-server.git
cd forms-server
2.0 Using the Makefile:
-
make run-batched # for CSV-based -
make run-sqlite # for SQLite-based
2.1 Batched Write Server:
- Navigate to the
batched-serverdirectory:cd batched-server - Run the server manually:
go run main.go - The server will start on
http://localhost:3000.
2.2 SQLite Server:
- Navigate to the
sqlite-serverdirectory:cd sqlite-server - Install dependencies (if not already installed):
go mod tidy - Run the server manually:
go run main.go - The server will start on
http://localhost:3000.
API Endpoints
Both servers expose the following endpoints:
-
GET /:- Returns a
200 OKstatus with a message indicating the server is running. - Example response:
"Batched Write Server is running"
- Returns a
-
POST /submit:- Accepts a form submission with an
emailfield. - Example request:
curl -X POST -d "email=user@example.com" http://localhost:3000/submit - Example response:
{"message": "data received"}
- Accepts a form submission with an
Server Implementations
1. Batched Write Server (CSV-based)
- Purpose: A dependency-free implementation for users who want minimalism and simplicity.
- Storage: Emails are appended to a CSV file (
emails.csv) in thebatched-serverdirectory. - Performance: Batches writes to reduce disk I/O, flushing every 5 seconds or after 100 emails.
- Format: Each row in the CSV file contains an email and a timestamp.
- Use Case: Ideal for lightweight deployments where external dependencies are not desired.
2. SQLite Server
- Purpose: A more robust implementation using SQLite for structured storage.
- Storage: Emails are stored in an SQLite database (
emails.db) in thesqlite-serverdirectory. - Features:
- Prevents duplicate emails with a unique constraint.
- Tracks the creation timestamp of each email.
- Use Case: Ideal for deployments where data integrity and querying capabilities are important.
Configuration
- Port: Both servers run on port
3000by default. To change the port, modify thePORTconstant in the respectivemain.gofile. - Storage Location:
- Batched Write Server: Emails are stored in
batched-server/emails.csv. - SQLite Server: Emails are stored in
sqlite-server/emails.db.
- Batched Write Server: Emails are stored in
Trade-offs
| Feature | Batched Write Server (CSV) | SQLite Server |
|---|---|---|
| Dependencies | None | Requires SQLite dependency |
| Storage | CSV file | SQLite database |
| Data Integrity | Basic | High (prevents duplicates) |
| Querying | Not supported | Supported |
| Performance | High (batched writes) | High (SQLite optimized) |
| Use Case | Minimalist, dependency-free | Robust, structured storage |
Contributing
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Languages
Go
69.6%
Shell
23.7%
Makefile
6.7%