repo

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package repo selects between concrete service.Repository / service.DB drivers (postgres, sqlite, memory) for the production binary's wiring code.

Each driver lives in its own sub-package — internal/repo/postgres for the SQL driver, internal/repo/sqlite for the pure-Go embedded/single-node driver, and internal/repo/memory for the in-process store used by tests. The split keeps each driver's dependencies isolated (postgres pulls in pgx; sqlite pulls in modernc.org/sqlite; memory pulls in nothing).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Built

type Built struct {
	Repository service.Repository
	DB         service.DB

	// ProjectStore is the control-plane registry store. It is non-nil
	// ONLY for the postgres driver — projects are a control-plane concern
	// and memory has no control plane. The composition root uses it
	// to seed the default project on boot. It shares Repository's pool, so
	// closing the repository releases it too; do not close it separately.
	ProjectStore *pgrepo.ProjectStore

	// AutoFormStore auto-forms a company tenant from a new user's email
	// domain at signup. Non-nil ONLY for the postgres driver; shares
	// Repository's pool.
	AutoFormStore *pgrepo.AutoFormStore

	// DomainStore, TenantStore, MembershipStore and LoginPolicyStore are the
	// per-project governance stores. They back the tenant domain-verification
	// RPCs (DomainStore/TenantStore/MembershipStore) and the login path's
	// LoginPolicy enforcement (TenantStore/DomainStore/LoginPolicyStore).
	// Non-nil ONLY for the postgres driver (the only one with a governance
	// plane); each shares Repository's pool.
	DomainStore      *pgrepo.DomainStore
	TenantStore      *pgrepo.TenantStore
	MembershipStore  *pgrepo.MembershipStore
	LoginPolicyStore *pgrepo.LoginPolicyStore

	// InvitationStore backs the tenant-invitation RPCs. Non-nil ONLY for the
	// postgres driver; shares Repository's pool.
	InvitationStore *pgrepo.InvitationStore

	// PlatformAdminStore backs the zero-config first-admin bootstrap
	// (CreateFirstPlatformAdmin). Non-nil ONLY for the postgres driver (the
	// only one with a platform_admins table); shares Repository's pool.
	PlatformAdminStore *pgrepo.PlatformAdminStore
}

Built bundles the constructed Repository + DB pair so callers can wire them into the service layer in one shot.

func Build

func Build(ctx context.Context, cfg Config, logger *zap.Logger) (*Built, error)

Build returns a Built configured per cfg.Driver.

func (*Built) ControlPlaneStore added in v0.19.0

func (b *Built) ControlPlaneStore() service.ControlPlaneProjectStore

ControlPlaneStore returns the control-plane project write-store as the driver-agnostic service.ControlPlaneProjectStore the admin RPCs use, or a true nil when this build has no control plane (memory) — avoiding the typed-nil trap.

func (*Built) DomainStoreIface added in v0.17.0

func (b *Built) DomainStoreIface() service.DomainStore

DomainStoreIface returns the domain governance store as a driver-agnostic interface, or a true nil when this build has no control plane (memory) — avoiding the typed-nil trap.

func (*Built) InvitationStoreIface added in v0.18.0

func (b *Built) InvitationStoreIface() service.InvitationStore

InvitationStoreIface returns the invitation governance store as a driver-agnostic interface, or a true nil when this build has no control plane (memory) — avoiding the typed-nil trap.

func (*Built) LoginGovernance added in v0.17.0

func (b *Built) LoginGovernance() *service.LoginGovernance

LoginGovernance returns the read-side governance bundle the login path consults to enforce a claimed tenant's LoginPolicy, or a true nil when this build has no governance plane (memory). Returning nil — rather than a bundle of typed-nil stores — keeps AuthService's nil check honest.

func (*Built) LoginPolicyStoreIface added in v1.3.0

func (b *Built) LoginPolicyStoreIface() service.LoginPolicyStore

LoginPolicyStoreIface returns the login-policy governance store as a driver-agnostic interface, or a true nil when this build has no governance plane (memory) — avoiding the typed-nil trap. It backs the operator LoginPolicy-authoring admin RPCs.

func (*Built) MembershipStoreIface added in v0.17.0

func (b *Built) MembershipStoreIface() service.MembershipStore

MembershipStoreIface returns the membership governance store as a driver-agnostic interface, or a true nil when this build has no control plane (memory) — avoiding the typed-nil trap.

func (*Built) PlatformAdminStoreIface added in v1.1.0

func (b *Built) PlatformAdminStoreIface() service.PlatformAdminStore

PlatformAdminStoreIface returns the platform-admin store as a driver-agnostic interface, or a true nil when this build has no control plane (memory) — avoiding the typed-nil trap.

func (*Built) ProjectResolver added in v0.16.0

func (b *Built) ProjectResolver() service.ProjectResolver

ProjectResolver returns the control-plane project resolver as a driver-agnostic interface, or a true nil when this build has no control plane (memory). It exists so callers avoid the typed-nil trap: assigning a nil *ProjectStore straight into a service.ProjectResolver variable yields a non-nil interface wrapping a nil pointer.

func (*Built) TenantAutoFormer added in v0.17.0

func (b *Built) TenantAutoFormer() service.TenantAutoFormStore

TenantAutoFormer returns the tenant auto-formation store as a driver-agnostic interface, or a true nil when this build has no control plane (memory) — avoiding the typed-nil trap.

func (*Built) TenantStoreIface added in v0.17.0

func (b *Built) TenantStoreIface() service.TenantStore

TenantStoreIface returns the tenant governance store as a driver-agnostic interface, or a true nil when this build has no control plane (memory) — avoiding the typed-nil trap.

type Config

type Config struct {
	// Driver is the chosen backend. Required.
	Driver Driver

	// ProjectID is the storage shard the boot-default Repository/DB binds
	// to (ADR-0002): the Project is identity's isolation shard, so the
	// data-plane partition is the project id. Per-request scopes are derived
	// from it via WithProject. Required for postgres.
	ProjectID string

	// Postgres-specific.
	PostgresDSN      string
	PostgresMaxConns int
	// PostgresConnTimeoutMs is the per-acquire pgx pool connection timeout in
	// milliseconds; Build converts it to a time.Duration for pgrepo.Config.
	// Zero leaves pgrepo's own DefaultConnTimeout in effect.
	PostgresConnTimeoutMs int
	PostgresAutoMigrate   bool

	// SQLite-specific. SQLitePath is the database file path or ":memory:".
	SQLitePath     string
	SQLiteMaxConns int

	// RequireVerifiedAuthDomain restricts a project's primary auth-domain
	// (the host that drives branded link URLs) to DNS-verified hostnames
	// when true (the safe default). When false, a deployer opts into letting
	// an unverified is_primary host drive branded links. Threaded into the
	// postgres ProjectStore resolver.
	RequireVerifiedAuthDomain bool
}

Config selects which driver to build and carries the parameters each driver needs.

type Driver

type Driver string

Driver names a concrete persistence backend.

const (
	// DriverPostgres targets a Postgres database via pgx/v5.
	DriverPostgres Driver = "postgres"
	// DriverMemory targets a process-local in-memory store, useful
	// for unit tests and local development.
	DriverMemory Driver = "memory"
	// DriverSQLite targets a pure-Go SQLite database (file or :memory:)
	// via modernc.org/sqlite — the lightweight embedded/single-node tier.
	DriverSQLite Driver = "sqlite"
)

Directories

Path Synopsis
Package conformance is a driver-agnostic test suite for service.Repository implementations.
Package conformance is a driver-agnostic test suite for service.Repository implementations.
Package memory is the in-process Repository driver.
Package memory is the in-process Repository driver.
Package postgres provides a Postgres-backed implementation of service.Repository for the identity service.
Package postgres provides a Postgres-backed implementation of service.Repository for the identity service.
Package sqlite is the pure-Go SQLite Repository driver — the lightweight / embedded backend tier (single file or :memory:), sitting between Postgres (production, multi-node) and memory (tests).
Package sqlite is the pure-Go SQLite Repository driver — the lightweight / embedded backend tier (single file or :memory:), sitting between Postgres (production, multi-node) and memory (tests).

Jump to

Keyboard shortcuts

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