Documentation
¶
Overview ¶
Example: Loading blocklist rules from PostgreSQL using sqlx
This example demonstrates how to implement a custom RuleLoader that fetches blocking rules from a PostgreSQL database using sqlx.
Required table schema:
CREATE TABLE blocklist (
id SERIAL PRIMARY KEY,
rule_type VARCHAR(10) NOT NULL CHECK (rule_type IN ('domain', 'url', 'regex')),
pattern VARCHAR(500) NOT NULL,
reason VARCHAR(255) DEFAULT 'blocked by policy',
category VARCHAR(100),
enabled BOOLEAN DEFAULT true,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX idx_blocklist_enabled ON blocklist(enabled) WHERE enabled = true;
To run this example:
go get github.com/jmoiron/sqlx go get github.com/lib/pq DATABASE_URL="postgres://user:pass@localhost/dbname?sslmode=disable" go run main.go
Click to show internal directories.
Click to hide internal directories.