db

package
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package db is glabs-web's MongoDB layer. It owns the connection and the collection access; everything above it works with the decoded documents.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

func Connect

func Connect(ctx context.Context, uri, database string) (*DB, error)

Connect opens the connection and verifies it with a ping, so a bad URI fails at startup rather than on the first query.

UseLocalTimeZone decodes the UTC that Mongo stores back into time.Local, which main sets to Europe/Berlin — so timestamps read out in the zone they were written in.

func (*DB) CountUsers

func (db *DB) CountUsers(ctx context.Context) (int64, error)

CountUsers reports how many users exist, so seeding can run only on an empty allowlist.

func (*DB) Disconnect

func (db *DB) Disconnect(ctx context.Context) error

func (*DB) EnsureUserIndexes

func (db *DB) EnsureUserIndexes(ctx context.Context) error

EnsureUserIndexes makes the email unique. Called once at startup.

func (*DB) GetUserByEmail

func (db *DB) GetUserByEmail(ctx context.Context, email string) (*model.User, error)

GetUserByEmail returns the user with the given email, or nil if there is none. The auth middleware treats nil as "not on the allowlist" — a 403 — so a missing user must be nil, nil rather than an error.

func (*DB) SaveUser

func (db *DB) SaveUser(ctx context.Context, user *model.User) error

SaveUser inserts or updates a user, keyed by email.

Jump to

Keyboard shortcuts

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