PGStream is a Go package that implements the io.ReadWriter interface backed by posgres and database/sql.
This allows you to pass around an io.Reader
or io.Writer
that can be shared across processes.
First, create a table with the following schema:
CREATE TABLE logs (
id SERIAL,
stream text not null,
text text
);
CREATE INDEX index_stream_on_logs ON logs USING btree (stream);
Then initialize a new pgstream engine:
rw := pgstream.New("mylogs", db)
io.WriteString(rw, "Log line")
io.Copy(os.Stdout, rw)