Documentation
¶
Overview ¶
Package config provides configuration loading and management for the registry server.
Index ¶
Constants ¶
const ( // SourceTypeGit is the type for registry data stored in Git repositories SourceTypeGit = "git" // SourceTypeAPI is the type for registry data fetched from API endpoints SourceTypeAPI = "api" // SourceTypeFile is the type for registry data stored in local files SourceTypeFile = "file" )
const ( // SourceFormatToolHive is the native ToolHive registry format SourceFormatToolHive = "toolhive" // SourceFormatUpstream is the upstream MCP registry format SourceFormatUpstream = "upstream" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIConfig ¶
type APIConfig struct {
// Endpoint is the base API URL (without path)
// The source handler will append the appropriate paths, for instance:
// - /v0/servers - List all servers (single response, no pagination)
// - /v0/servers/{name} - Get specific server (future)
// - /v0/info - Get registry metadata (future)
// Example: "http://my-registry-api.default.svc.cluster.local/api"
Endpoint string `yaml:"endpoint"`
}
APIConfig defines API source configuration for ToolHive Registry APIs
type Config ¶
type Config struct {
// RegistryName is the name/identifier for this registry instance
// Defaults to "default" if not specified
RegistryName string `yaml:"registryName,omitempty"`
Source SourceConfig `yaml:"source"`
SyncPolicy *SyncPolicyConfig `yaml:"syncPolicy,omitempty"`
Filter *FilterConfig `yaml:"filter,omitempty"`
Database *DatabaseConfig `yaml:"database,omitempty"`
}
Config represents the root configuration structure
func LoadConfig ¶
LoadConfig loads and parses configuration from a YAML file
func (*Config) GetRegistryName ¶
GetRegistryName returns the registry name, using "default" if not specified
type DatabaseConfig ¶
type DatabaseConfig struct {
// Host is the database server hostname or IP address
Host string `yaml:"host"`
// Port is the database server port
Port int `yaml:"port"`
// User is the database username
User string `yaml:"user"`
// PasswordFile is the path to a file containing the database password
// This is the recommended approach for production deployments
// The file should contain only the password with optional trailing whitespace
PasswordFile string `yaml:"passwordFile,omitempty"`
// Database is the database name
Database string `yaml:"database"`
// SSLMode is the SSL mode for the connection (disable, require, verify-ca, verify-full)
SSLMode string `yaml:"sslMode,omitempty"`
// MaxOpenConns is the maximum number of open connections to the database
MaxOpenConns int32 `yaml:"maxOpenConns,omitempty"`
// MaxIdleConns is the maximum number of idle connections in the pool
MaxIdleConns int32 `yaml:"maxIdleConns,omitempty"`
// ConnMaxLifetime is the maximum lifetime of a connection (e.g., "1h", "30m")
ConnMaxLifetime string `yaml:"connMaxLifetime,omitempty"`
}
DatabaseConfig defines database connection settings
func (*DatabaseConfig) GetConnectionString ¶
func (d *DatabaseConfig) GetConnectionString() (string, error)
GetConnectionString builds a PostgreSQL connection string with proper password handling. The password is URL-escaped to handle special characters safely.
func (*DatabaseConfig) GetPassword ¶
func (d *DatabaseConfig) GetPassword() (string, error)
GetPassword returns the database password using the following priority: 1. Read from PasswordFile if specified 2. Read from THV_DATABASE_PASSWORD environment variable
The password from file will have leading/trailing whitespace trimmed.
type FileConfig ¶
type FileConfig struct {
// Path is the path to the registry.json file on the local filesystem
// Can be absolute or relative to the working directory
Path string `yaml:"path"`
}
FileConfig defines local file source configuration
type FilterConfig ¶
type FilterConfig struct {
Names *NameFilterConfig `yaml:"names,omitempty"`
Tags *TagFilterConfig `yaml:"tags,omitempty"`
}
FilterConfig defines filtering rules for registry entries
type GitConfig ¶
type GitConfig struct {
// Repository is the Git repository URL (HTTP/HTTPS/SSH)
Repository string `yaml:"repository"`
// Branch is the Git branch to use (mutually exclusive with Tag and Commit)
Branch string `yaml:"branch,omitempty"`
// Tag is the Git tag to use (mutually exclusive with Branch and Commit)
Tag string `yaml:"tag,omitempty"`
// Commit is the Git commit SHA to use (mutually exclusive with Branch and Tag)
Commit string `yaml:"commit,omitempty"`
// Path is the path to the registry file within the repository
Path string `yaml:"path,omitempty"`
}
GitConfig defines Git source settings
type NameFilterConfig ¶
type NameFilterConfig struct {
Include []string `yaml:"include,omitempty"`
Exclude []string `yaml:"exclude,omitempty"`
}
NameFilterConfig defines name-based filtering
type Option ¶
type Option func(*loaderConfig) error
Option defines the interface for configuration options
func WithConfigPath ¶
WithConfigPath loads configuration from a YAML file
type SourceConfig ¶
type SourceConfig struct {
Type string `yaml:"type"`
Format string `yaml:"format"`
Git *GitConfig `yaml:"git,omitempty"`
API *APIConfig `yaml:"api,omitempty"`
File *FileConfig `yaml:"file,omitempty"`
}
SourceConfig defines the data source configuration
type SyncPolicyConfig ¶
type SyncPolicyConfig struct {
Interval string `yaml:"interval"`
}
SyncPolicyConfig defines synchronization settings
type TagFilterConfig ¶
type TagFilterConfig struct {
Include []string `yaml:"include,omitempty"`
Exclude []string `yaml:"exclude,omitempty"`
}
TagFilterConfig defines tag-based filtering