middleware

package
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Tenancy

func Tenancy(db *sql.DB, log Logger, getTenantIDFromCtx func(context.Context) string) func(next http.Handler) http.Handler

Tenancy is a middleware that injects a tenanted *sql.Conn into the context of each request. This middleware accepts a function which should extract the current tenant from context. The expectation is that you will have some auth middleware which can inject the current tenant into the ctx in a previous step.

When a query is made using the Pool, a new connection will be opened and tenancy applied to it. These connections are tracked internally and will be closed at the end of the request

If you start a transaction from the Pool, a single connection will be opened and used for all queries for the duration of the transaction

You may also open a single Conn from the pool which will be closed when the pool is closed

Types

type Logger added in v1.1.1

type Logger interface {
	Error(err error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL