regionpeers

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package regionpeers lets a single-region service handler serve extra regions by lazily building one sibling handler per non-home region.

Index

Constants

View Source
const (

	// MaxPeers bounds siblings per Set; AWS has well under 64 regions.
	MaxPeers = 64
)

Variables

This section is empty.

Functions

func Backend

func Backend[T, I any](backendFor func(region string) I, region string) (T, bool)

Backend returns the backend serving region from backendFor (a handler's BackendFor method) as T; ok is false when it is not a T.

func First

func First(regions ...string) string

First returns the first non-empty region, or "" (the home region).

func ValidRegion

func ValidRegion(region string) bool

ValidRegion reports whether region looks like an AWS region code.

Types

type Set

type Set[T any] struct {
	// contains filtered or unexported fields
}

Set holds the lazily built per-region siblings of one home handler. A nil *Set is valid and means the service serves only its home region.

func New

func New[T any](home string, build func(region string) *T) *Set[T]

New returns a Set whose siblings are made by build. Requests for home or an empty region are never routed to a sibling.

func (*Set[T]) All

func (s *Set[T]) All() []*T

All returns the siblings built so far, ordered by region, without removing them.

func (*Set[T]) Drain

func (s *Set[T]) Drain() []*T

Drain removes and returns every sibling so the caller can reset or close them.

func (*Set[T]) Get

func (s *Set[T]) Get(region string) *T

Get returns region's sibling, creating it on first use; nil means the home handler serves (home region, malformed region, or MaxPeers reached), so garbage regions cannot grow siblings.

func (*Set[T]) Restore

func (s *Set[T]) Restore(data []byte, restore func(*T, []byte) error, closeFn func(*T)) error

Restore rebuilds the siblings from the "regions" object in data, dropping any that exist now. Data without that key (older snapshots) just clears them.

func (*Set[T]) Snapshot

func (s *Set[T]) Snapshot(base []byte, snap func(*T) []byte) []byte

Snapshot returns base unchanged when no sibling exists, so single-region snapshots stay byte-identical; otherwise it adds a "regions" object.

Jump to

Keyboard shortcuts

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