resource

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package resource coordinates long-lived system components and shared state. It manages the lifecycle of caches, metrics, health registries, and environment variables.

Package resource defines context structures for routing and traffic handling. It facilitates dependency injection for HTTP route and proxy handlers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Env

type Env struct {
	Global *mappo.Concurrent[string, expect.Value]
	Route  *mappo.Concurrent[string, expect.Value]
	// contains filtered or unexported fields
}

func (*Env) GetGlobal

func (e *Env) GetGlobal() *mappo.Concurrent[string, expect.Value]

GetGlobal safely retrieves the current global env map pointer

type Option

type Option func(*Resource)

func WithAuthCache

func WithAuthCache(cache *mappo.Cache) Option

WithAuthCache sets the cache used for storing successful authentication results. It reduces the load on external auth providers by caching tokens and session state.

func WithCacheSizes

func WithCacheSizes(routeMax, tcpMax, authMax, gzMax int) Option

WithCacheSizes reinitializes internal caches with the specified maximum capacities. It clears existing data to ensure the new size constraints are applied immediately.

func WithCustomHTTPClient

func WithCustomHTTPClient(client *http.Client) Option

WithCustomHTTPClient assigns a pre-configured HTTP client to the resource manager. This client is used for all outgoing requests including auth and serverless REST.

func WithCustomTransport

func WithCustomTransport(transport *http.Transport) Option

WithCustomTransport sets a specialized HTTP transport for backend proxying. It is primarily used to tune connection pooling and timeout behavior.

func WithDoctor

func WithDoctor(doctor *jack.Doctor) Option

WithDoctor attaches a health monitor to track the status of backend patients. It ensures that background health checks are executed according to their interval.

func WithGzCache

func WithGzCache(cache *mappo.Cache) Option

WithGzCache sets the cache instance for pre-compressed static content. It allows the server to serve gzipped payloads without re-compressing them.

func WithHealth

func WithHealth(registry *health.Registry) Option

WithHealth replaces the current backend health registry. It allows for fresh health score tracking during configuration updates.

func WithKeeper

func WithKeeper(k *keeper.Keeper) Option

WithKeeper sets the Keeper instance for the Resource, allowing it to manage and coordinate subsystem operations.

func WithLifetime

func WithLifetime(l *jack.Lifetime) Option

WithLifetime sets the Lifetime field of a Resource to the provided Lifetime instance.

func WithLifetimeManager

func WithLifetimeManager(lm *jack.Lifetime) Option

WithLifetimeManager configures the TTL manager for dynamic cluster resources. It tracks the expiration of temporary routes and security tokens.

func WithLogger

func WithLogger(logger *ll.Logger) Option

WithLogger sets the system-wide logger for the resource manager. It allows for namespaced logging across all managed proxy components.

func WithMetrics

func WithMetrics(registry *metrics.Registry) Option

WithMetrics replaces the current metrics registry with a new instance. This is used during reloads to reset or reconfigure telemetry collection.

func WithReaper

func WithReaper(reapHandler func(context.Context, string)) Option

WithReaper initializes the cache reaper with a custom cleanup handler. It automatically removes expired entries from the route and auth caches.

func WithRouteCache

func WithRouteCache(cache *mappo.Cache) Option

WithRouteCache sets a specific cache instance for HTTP route lookup results. It ensures that high-frequency route matching remains performant under load.

func WithShutdown

func WithShutdown(shutdown *jack.Shutdown) Option

WithShutdown configures the global shutdown manager for the resource. It ensures that all registered cleanup functions are executed on exit.

func WithTCPCache

func WithTCPCache(cache *mappo.Cache) Option

WithTCPCache sets a specific cache instance for TCP stream mapping results. This provides rapid lookup for SNI and port-based connection routing.

type Patience

type Patience struct {
	Route *alaye.Route
	// contains filtered or unexported fields
}

type Proxy

type Proxy struct {
	Resource    *Resource
	Global      *alaye.Global
	Host        *alaye.Host
	SharedState woos.SharedState
	CookMgr     *cook.Manager
	IPMgr       *zulu.IPManager
	Orch        *orchestrator.Manager
}

func (Proxy) Logger

func (p Proxy) Logger() *ll.Logger

Logger provides access to the namespaced system logger from the resource manager. This ensures that all proxy-related events are logged consistently.

func (Proxy) Validate

func (p Proxy) Validate() error

Validate ensures that all mandatory proxy dependencies are correctly initialized. It performs integrity checks on the resource, global config, and host configuration.

type Resource

type Resource struct {
	Metrics    *metrics.Registry
	Health     *health.Registry
	RouteCache *mappo.Cache
	TCPCache   *mappo.Cache
	AuthCache  *mappo.Cache
	GzCache    *mappo.Cache

	TimeStore *mappo.Concurrent[string, time.Time]

	Transport  *http.Transport
	HTTPClient *http.Client

	Logger     *ll.Logger
	Doctor     *jack.Doctor
	Reaper     *jack.Reaper
	Shutdown   *jack.Shutdown
	Lifetime   *jack.Lifetime
	Keeper     *keeper.Keeper
	Janitor    *jack.Pool
	Background *jack.Pool

	Env *Env
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) *Resource

New constructs a Resource manager and initializes all core sub-systems. It sets up thread-safe registries and default networking transports.

func (*Resource) Apply

func (m *Resource) Apply(opts ...Option)

Apply executes a list of configuration options on the Resource instance. This is used for both initial setup and dynamic runtime re-configuration.

func (*Resource) Close

func (m *Resource) Close()

Close gracefully terminates all background processes and clears internal registries. It ensures that idle connections are closed and cache entries are properly disposed of.

func (*Resource) Counter

func (m *Resource) Counter() uint64

Counter returns the current global sequence value from the resource manager. This value is used for generating unique IDs across various server sub-systems.

func (*Resource) NextID

func (m *Resource) NextID() uint64

NextID increments and returns the global counter to provide a unique identifier. It is used for tracking requests, tasks, and backend patient registration.

func (*Resource) UpdateGlobal

func (m *Resource) UpdateGlobal(newEnv map[string]expect.Value)

UpdateGlobal creates a new concurrent map, populates it, and safely swaps the pointer so readers never see partial state.

func (*Resource) Validate

func (m *Resource) Validate() error

Validate checks the integrity of the Resource manager before it starts processing traffic. It returns an error if critical networking or monitoring components are uninitialized.

Jump to

Keyboard shortcuts

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