refactor: follow the google go style guide
Document every package and exported identifier, return the log level from NewLogger instead of keeping it in a package variable, and stop tests from mutating the argon2 parameters. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
048e114fd9
commit
d20225982a
21 files changed
+147
-36
No files matched your search
@@ -1,3 +1,5 @@
|
||||
// Package tenant runs queries inside a row-level-security context. All
|
||||
// database access from request handlers must go through DB.Tx.
|
||||
package tenant
|
||||
|
||||
import (
|
||||
@@ -21,6 +23,7 @@ type Scope struct {
|
||||
global bool
|
||||
}
|
||||
|
||||
// Org scopes to one organization. user may be uuid.Nil for background work.
|
||||
func Org(org, user uuid.UUID) Scope { return Scope{OrgID: org, UserID: user} }
|
||||
|
||||
// User grants access to the user's own memberships and the orgs behind them,
|
||||
@@ -35,12 +38,17 @@ func Global() Scope { return Scope{global: true} }
|
||||
// cross-tenant, never for request handling.
|
||||
func System() Scope { return Scope{system: true} }
|
||||
|
||||
// ErrNoScope is returned by Tx for the zero Scope.
|
||||
var ErrNoScope = errors.New("tenant: empty scope")
|
||||
|
||||
// DB wraps a pool so that every transaction carries a Scope.
|
||||
type DB struct{ pool *pgxpool.Pool }
|
||||
|
||||
// New returns a DB using pool.
|
||||
func New(pool *pgxpool.Pool) *DB { return &DB{pool: pool} }
|
||||
|
||||
// Tx runs fn in a transaction whose row-level-security settings come from s.
|
||||
// The transaction commits if fn returns nil and rolls back otherwise.
|
||||
func (d *DB) Tx(ctx context.Context, s Scope, fn func(*store.Queries) error) error {
|
||||
if s == (Scope{}) {
|
||||
return ErrNoScope
|
||||
|
||||
Reference in new issue
Block a user