modulepackage
0.0.0-20250106230832-9a330938ded7
Repository: https://github.com/edgeflare/pgo.git
Documentation: pkg.go.dev
# README
pgo (/pɪɡəʊ/
): Postgres integrations in Go
This is a piecemeal collection of code snippets, which has evolved from my Postgres+Go projects whenever they were reused, without any plan/structure.
Now I'm (forcibly) moving from applications to this repo the boilerplate / heavy-lifting around:
- net/http.Handler
- router
- middleware (authentication, logging, CORS, RequestID, ...)
- Postgres middleware attaches a pgxpool.Conn to request context for authorized user; useful for RLS
- Retrieval Augmented Generation (RAG)
- fetch embeddings from LLM APIs (OpenAI, Groq, Anthropic, Google, Ollama, ...)
- utils for pgvector search, augmented generation
- Pipelines (realtime/batch)
- Postgres' Logical Replication (optionally LISTEN/NOTIFY)
- MQTT, Kafka, HTTP, ClickHouse, gRPC (add more by writing plugins yourself)
Usage
-
As a standalone binary for publishing Postgres CDC to Kafka, MQTT, ClickHouse, etc, see docs/postgres-cdc.md
It's also possible to import functions, etc. This reusability seems helpful, mostly because I'm learning by being forced to write reliable code that other code might depend on. Most of it actually isn’t dependable, yet. If you're curious, start by browsing the examples, skimming over any doc.go, *.md files.
Contributing
Please see CONTRIBUTING.md.
License
Apache License 2.0
# Packages
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Functions
BasicAuthUser retrieves the authenticated username from the context.
BindOrError decodes the JSON body of an HTTP request, r, into the given destination object, dst.
Blob writes a binary response with the given status code and data.
Conn retrieves the OIDC user and a pgxpool.Conn from the request context.
ConnWithRole retrieves the OIDC user, a pgxpool.Conn, and checks for a role from the request context.
DefaultPool returns the default PostgreSQL connection pool.
Error sends a JSON response with an error code and message.
HTML writes an HTML response with the given status code and HTML content.
InitDefaultPool initializes the default PostgreSQL connection pool and returns it.
JSON writes a JSON response with the given status code and data.
NewRouter creates a new instance of Router with the given options.
OIDCUser extracts the OIDC user from the request context.
Text writes a plain text response with the given status code and text content.
WithServerOptions returns a RouterOptions function that sets custom http.Server options.
WithTLS provides a simplified way to enable HTTPS in your router.
# Constants
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Variables
No description provided by the author
No description provided by the author
# Structs
ErrorResponse represents a structured error response.
Router is the main structure for handling HTTP routing and middleware.
# Type aliases
No description provided by the author
Middleware defines a function type that represents a middleware.
RouterOptions is a function type that represents options to configure a Router.