A very minimal simulation of the LIBR system implementing decentralized moderation using Go concurrency, PostgreSQL, and RESTful APIs.
Simulate decentralized moderation using goroutines, channels, and context timeouts. Provide basic APIs for:
- Submitting a message (
POST /submit) - Retrieving messages by timestamp (
GET /fetch/{timestamp}) - Retrieve all stored messages regardless of timestamp (
GET /fetchall)
LIBR Prototype/
├── cmd/
│ └── main.go # Starts the server
├── controllers/
│ └── handler.go # HTTP handler logic
├── db/
│ ├── db.go # DB connection setup
│ └── message_repo.go # DB operations
├── moderator/
│ └── moderator.go # Simulates moderation with goroutines
├── model/
│ └── message.go # Data models
├── router/
│ └── router.go # Route registration
├── .env # PostgreSQL credentials
├── go.mod # Module file
└── README.md
sudo apt update
sudo apt install postgresql postgresql-contribCREATE DATABASE libr;
\c libr
CREATE TABLE messages (
id UUID PRIMARY KEY,
content TEXT NOT NULL,
timestamp BIGINT NOT NULL,
status VARCHAR(10) NOT NULL
);Create a .env file in the root directory:
DB_URL=Replace credentials with yours if needed.
git clone <your-repo-url>
cd "LIBR Prototype"
go mod tidy
go build -o server ./cmd
./serverServer will start on: http://localhost:4000
Submit a message for moderation.
Request Payload:
{
"content": "This is a test message."
}Sample Response (Approved):
{
"id": "generated-uuid",
"timestamp": 1744219507,
"status": "approved"
}Sample Response (Rejected):
{
"id": "generated-uuid",
"timestamp": 1744219507,
"status": "rejected"
}Retrieve all messages submitted at a specific timestamp.
Sample Response:
[
{
"id": "unique-id",
"content": "This is a test message.",
"timestamp": 1744219507,
"status": "approved"
}
]Retrieve all messages regardless of timestamp.
Sample Response:
[
{
"id": "unique-id",
"content": "This is a test message.",
"timestamp": 1744219507,
"status": "approved"
}
{
"id": "unique-id",
"content": "This is a test message.",
"timestamp": 1744219507,
"status": "approved"
}
{
"id": "unique-id",
"content": "This is a test message.",
"timestamp": 1744219507,
"status": "approved"
}
]Each message is sent to 3 simulated moderators. Moderators:
- Use goroutines for concurrency.
- Introduce random delays (
1-3s) to mimic real processing. - Randomly approve/reject the message.
- Respond via channels.
- Have a 3s timeout using
context.WithTimeout.
The message is approved if at least 2 moderators approve, otherwise it's rejected.
gorilla/mux: Routingpgx: PostgreSQL drivergoogle/uuid: UUID generatorjoho/godotenv: Load environment variables
Use Postman to test:
- DB credentials are stored in
.env. Do not commit.envto version control. - This is a prototype. Avoid using it in production environments.




