Hi nerds! Last week, i had the genius idea to organize a livestream event for no fucking reason.
Now, i need a system to handle the tickets, and yeah if you go through my github you'll know i already have at least two versions of exactly that. Buttttt those are in Typescript, and i'm learning Go rn. So, i'm following the HTTP Server section of Go By Example, and i'll adapt it to work for my use case. Feel free to comment!
xoxo <3
Timmy
- Go 1.24+
- A PostgreSQL database (the project uses Neon by default)
git clone <repo>
cd bills
cp .env.sample .env # fill in your DATABASE_URL
go run .The server starts on the port defined in .env (default 9000).
| Variable | Required | Default | Description |
|---|---|---|---|
DATABASE_URL |
yes | — | Postgres connection string |
PORT |
no | 9000 |
Port the server listens on |
BASE_URL |
no | http://localhost:9000 |
Base URL for generating QR code URLs |
Create a .env file in the project root (it is git-ignored):
DATABASE_URL=postgres://user:password@localhost:5432/dbname
PORT=9000Interactive docs are available at /docs/ when the server is running.
The raw OpenAPI spec is at /docs/openapi.yaml.
| Method | Path | Description |
|---|---|---|
POST |
/qrcodes |
Create a ticket (ID is auto-generated) |
GET |
/qrcodes |
List all tickets |
GET |
/qrcodes/{id} |
Get a ticket by ID |
GET |
/qrcodes/phone/{phone} |
Get a ticket by client phone number |
PATCH |
/qrcodes/{id}/use |
Mark a ticket as used |
DELETE |
/qrcodes/{id} |
Delete a ticket |
GET |
/image/{id} |
Get QR code image (PNG) |
GET |
/scan/{id} |
Scan a ticket (marks as used, returns HTML page) |
curl -X POST http://localhost:9000/qrcodes \
-H "Content-Type: application/json" \
-d '{"image": "<base64>", "client_number": "+213XXXXXXXXX"}'{
"id": "550e8400-e29b-41d4-a716-446655440000",
"image": "<base64>",
"client_number": "+213XXXXXXXXX",
"used": false
}curl -X PATCH http://localhost:9000/qrcodes/550e8400-e29b-41d4-a716-446655440000/useCREATE TABLE qrcodes (
id TEXT PRIMARY KEY,
image TEXT NOT NULL,
client_number TEXT NOT NULL UNIQUE,
used BOOLEAN NOT NULL DEFAULT false,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
used_at TIMESTAMPTZ
);