Help us shape the future of Go! Take the 2026 Go Developer Survey

readopt

package
v0.6.7 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package readopt controls the filters a generated read applies by default.

Every query-based read excludes soft-deleted rows, excludes snapshots, and scopes to the caller's tenant. Those are the right defaults, and they are applied without being asked for — which is precisely why there has to be an explicit way to say otherwise. An escape hatch nobody can find is a reason to bypass the repository entirely.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// IncludeDeleted drops the "not deleted" filter.
	IncludeDeleted bool
	// OnlyDeleted returns just the deleted rows, within the restore window.
	OnlyDeleted bool
	// IncludeSnapshots drops the "live version only" filter.
	IncludeSnapshots bool
	// SkipTenantScope drops the tenant filter. It exists for administrative
	// tooling and cross-tenant reporting, and for nothing a request handler
	// should ever do.
	SkipTenantScope bool
	// SkipOwnerScope drops the "rows the caller created" filter, on a table that
	// has one.
	//
	// The only option here that a request handler does set, and the direction is
	// the reason it is safe to: the narrow read is what happens when nobody says
	// anything, so a handler that forgets this returns too little rather than too
	// much. Widening is the thing somebody had to ask for and hold a permission
	// for.
	SkipOwnerScope bool
}

Config is the resolved set of options.

func Apply

func Apply(opts []Option) (Config, error)

Apply resolves a set of options.

Contradictory options are an error rather than a precedence rule. Asking for deleted rows and only-deleted rows at once means the caller has confused themselves, and quietly picking one would hide that.

Example

A generated read excludes soft-deleted rows, excludes snapshots and scopes to the caller's tenant without being asked. These are how a caller says otherwise, and Apply is what a repository resolves them with.

package main

import (
	"fmt"

	"github.com/simonjanss/rig/runtime/readopt"
)

func main() {
	cfg, err := readopt.Apply([]readopt.Option{readopt.WithDeleted()})
	if err != nil {
		panic(err)
	}

	fmt.Println("deleted rows included:", cfg.IncludeDeleted)
	fmt.Println("snapshots included:   ", cfg.IncludeSnapshots)

}
Output:
deleted rows included: true
snapshots included:    false
Example (Contradiction)

Contradictory options are an error rather than a precedence rule. Asking for deleted rows and only-deleted rows at once means the caller has confused themselves, and quietly picking one would hide that.

package main

import (
	"fmt"

	"github.com/simonjanss/rig/runtime/readopt"
)

func main() {
	_, err := readopt.Apply([]readopt.Option{
		readopt.WithDeleted(),
		readopt.WithOnlyDeleted(),
	})

	fmt.Println(err)

}
Output:
BadRequest: WithDeleted and WithOnlyDeleted contradict each other
Example (Defaults)

No options is the narrow read, which is the direction that makes forgetting one safe: a handler that says nothing returns too little rather than too much.

package main

import (
	"fmt"

	"github.com/simonjanss/rig/runtime/readopt"
)

func main() {
	cfg, err := readopt.Apply(nil)
	if err != nil {
		panic(err)
	}

	fmt.Printf("%+v\n", cfg)

}
Output:
{IncludeDeleted:false OnlyDeleted:false IncludeSnapshots:false SkipTenantScope:false SkipOwnerScope:false}

type Option

type Option func(*Config)

Option adjusts a read.

func WithDeleted

func WithDeleted() Option

WithDeleted includes soft-deleted rows alongside live ones.

func WithOnlyDeleted

func WithOnlyDeleted() Option

WithOnlyDeleted returns only soft-deleted rows still inside the restore window — the "trash" view.

func WithSnapshots

func WithSnapshots() Option

WithSnapshots includes historical versions alongside live rows.

func WithoutOwnerScope

func WithoutOwnerScope() Option

WithoutOwnerScope reads every row in the tenant, not only the caller's own.

func WithoutTenantScope

func WithoutTenantScope() Option

WithoutTenantScope reads across every tenant.

Jump to

Keyboard shortcuts

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