multiserver

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package multiserver provides support for managing connections to multiple DataHub servers.

Index

Constants

View Source
const DefaultConnectionName = "datahub"

DefaultConnectionName is the fallback name for the primary connection.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Default is the display name of the primary connection.
	// This can be customized via DATAHUB_CONNECTION_NAME env var.
	// Defaults to "datahub" if not specified.
	Default string

	// Primary is the primary connection configuration (from DATAHUB_* env vars).
	Primary client.Config

	// Connections maps connection names to their configurations.
	// The primary connection is always available under the Default name.
	Connections map[string]ConnectionConfig
}

Config holds configuration for multiple DataHub connections.

func FromEnv

func FromEnv() (Config, error)

FromEnv builds a multi-server configuration from environment variables.

Primary server configuration comes from standard DATAHUB_* variables. Additional servers come from DATAHUB_ADDITIONAL_SERVERS as JSON:

{"staging": {"url": "https://staging.datahub.example.com", "token": "xxx"}}

The primary connection name can be customized via DATAHUB_CONNECTION_NAME (defaults to "datahub").

Additional servers inherit token, timeout, retry_max, etc. from the primary if not explicitly specified.

func (Config) ClientConfig

func (c Config) ClientConfig(name string) (client.Config, error)

ClientConfig returns a client.Config for the named connection. Returns the primary config if name is empty or matches the default connection name. Returns an error if the connection name is not found.

func (Config) ConnectionCount

func (c Config) ConnectionCount() int

ConnectionCount returns the total number of connections (including default).

func (Config) ConnectionInfos

func (c Config) ConnectionInfos() []ConnectionInfo

ConnectionInfos returns information about all connections for display.

func (Config) ConnectionNames

func (c Config) ConnectionNames() []string

ConnectionNames returns the names of all available connections. Always includes the primary connection name as the first entry.

type ConnectionConfig

type ConnectionConfig struct {
	// URL is the DataHub GMS URL (required for additional servers).
	URL string `json:"url"`

	// Token is the personal access token. Inherits from primary if empty.
	Token string `json:"token,omitempty"`

	// Timeout is the request timeout in seconds. Inherits from primary if zero.
	Timeout int `json:"timeout,omitempty"`

	// RetryMax is the maximum retry attempts. Inherits from primary if zero.
	RetryMax int `json:"retry_max,omitempty"`

	// DefaultLimit is the default search result limit. Inherits from primary if zero.
	DefaultLimit int `json:"default_limit,omitempty"`

	// MaxLimit is the maximum allowed limit. Inherits from primary if zero.
	MaxLimit int `json:"max_limit,omitempty"`

	// MaxLineageDepth is the maximum lineage traversal depth. Inherits from primary if zero.
	MaxLineageDepth int `json:"max_lineage_depth,omitempty"`

	// WriteEnabled enables write operations for this connection.
	// nil = inherit from toolkit config, true/false = explicit override.
	WriteEnabled *bool `json:"write_enabled,omitempty"`
}

ConnectionConfig defines configuration for a single DataHub connection. Fields that are empty/zero inherit from the primary connection.

type ConnectionInfo

type ConnectionInfo struct {
	Name      string `json:"name"`
	URL       string `json:"url"`
	IsDefault bool   `json:"is_default"`
}

ConnectionInfo holds display information about a connection.

type Manager

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

Manager manages connections to multiple DataHub servers. It lazily creates client connections on first use.

func NewManager

func NewManager(cfg Config) *Manager

NewManager creates a new connection manager with the given configuration. Clients are created lazily on first access, not at construction time.

func NewManagerFromEnv

func NewManagerFromEnv() (*Manager, error)

NewManagerFromEnv creates a Manager using configuration from environment variables.

func SingleClientManager

func SingleClientManager(c *client.Client, cfg client.Config) *Manager

SingleClientManager creates a Manager with only a default connection. This is useful for backwards compatibility with code that uses a single client.

func (*Manager) Client

func (m *Manager) Client(name string) (*client.Client, error)

Client returns the DataHub client for the named connection. If name is empty, returns the primary connection's client. Clients are created lazily and cached for reuse.

func (*Manager) Close

func (m *Manager) Close() error

Close closes all open client connections.

func (*Manager) Config

func (m *Manager) Config() Config

Config returns the manager's configuration.

func (*Manager) ConnectionCount

func (m *Manager) ConnectionCount() int

ConnectionCount returns the number of configured connections.

func (*Manager) ConnectionInfos

func (m *Manager) ConnectionInfos() []ConnectionInfo

ConnectionInfos returns information about all configured connections.

func (*Manager) Connections

func (m *Manager) Connections() []string

Connections returns the names of all configured connections.

func (*Manager) DefaultClient

func (m *Manager) DefaultClient() (*client.Client, error)

DefaultClient returns the default (primary) connection's client.

func (*Manager) HasConnection

func (m *Manager) HasConnection(name string) bool

HasConnection returns true if the named connection exists.

Jump to

Keyboard shortcuts

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