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

region

package
v0.87.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// RegionKey is the context key for the active region.
	RegionKey contextKey = "region"
)

Variables

This section is empty.

Functions

func ContextWithRegion

func ContextWithRegion(ctx context.Context, region string) context.Context

ContextWithRegion returns a context with the region set.

func RegionFromContext

func RegionFromContext(ctx context.Context) string

RegionFromContext extracts the region from the context.

Types

type DataResidencyEnforcer

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

DataResidencyEnforcer validates that data operations respect tenant residency requirements.

func NewDataResidencyEnforcer

func NewDataResidencyEnforcer() *DataResidencyEnforcer

NewDataResidencyEnforcer creates a new enforcer.

func (*DataResidencyEnforcer) Check

func (e *DataResidencyEnforcer) Check(tenantID, region string) error

Check validates that a region is allowed for a given tenant. Returns nil if the region is permitted or no rule is configured.

func (*DataResidencyEnforcer) CheckDataClass

func (e *DataResidencyEnforcer) CheckDataClass(tenantID string, regionCfg RegionConfig) error

CheckDataClass validates that a region supports the required data classification.

func (*DataResidencyEnforcer) GetRule

func (e *DataResidencyEnforcer) GetRule(tenantID string) (DataResidencyRule, bool)

GetRule returns the residency rule for a tenant.

func (*DataResidencyEnforcer) RemoveRule

func (e *DataResidencyEnforcer) RemoveRule(tenantID string)

RemoveRule removes a tenant's residency rule.

func (*DataResidencyEnforcer) SetRule

func (e *DataResidencyEnforcer) SetRule(rule DataResidencyRule)

SetRule configures the residency rule for a tenant.

type DataResidencyRule

type DataResidencyRule struct {
	TenantID       string
	AllowedRegions []string
	DataClass      string // e.g. "pii", "general", "restricted"
}

DataResidencyRule maps a tenant to the regions where its data may reside.

type RegionConfig

type RegionConfig struct {
	// Name is the unique identifier for this region (e.g. "us-east-1").
	Name string
	// Endpoint is the base URL for this region's API.
	Endpoint string
	// Primary indicates whether this is the primary region.
	Primary bool
	// AllowedDataClasses lists the data classification levels this region may store.
	AllowedDataClasses []string
}

RegionConfig describes a deployment region.

type RegionRouter

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

RegionRouter routes requests to the appropriate region based on tenant residency rules and region availability.

func NewRegionRouter

func NewRegionRouter(enforcer *DataResidencyEnforcer) *RegionRouter

NewRegionRouter creates a new region router.

func (*RegionRouter) AddRegion

func (r *RegionRouter) AddRegion(cfg RegionConfig)

AddRegion registers a region.

func (*RegionRouter) GetRegion

func (r *RegionRouter) GetRegion(name string) (RegionConfig, bool)

GetRegion returns a specific region's config.

func (*RegionRouter) PrimaryRegion

func (r *RegionRouter) PrimaryRegion() string

PrimaryRegion returns the primary region name.

func (*RegionRouter) Regions

func (r *RegionRouter) Regions() []RegionConfig

Regions returns all configured regions.

func (*RegionRouter) RemoveRegion

func (r *RegionRouter) RemoveRegion(name string)

RemoveRegion unregisters a region.

func (*RegionRouter) Route

func (r *RegionRouter) Route(tenantID string) (RegionConfig, error)

Route returns the best region for a tenant request. It checks residency rules first, then falls back to the primary region.

Jump to

Keyboard shortcuts

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