config

package
v0.28.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 11 Imported by: 0

README

Config Package (internal/config)

Server configuration loading and hot-reload support.

Overview

This package handles YAML-based configuration for the hotplexd server, including engine settings, server options, and security configuration.

Key Types

type ServerConfig struct {
    Engine   EngineConfig
    Server   ServerSettings
    Security SecurityConfig
}

type EngineConfig struct {
    Timeout         time.Duration
    IdleTimeout     time.Duration
    WorkDir         string
    SystemPrompt    string
    AllowedTools    []string
    DisallowedTools []string
}

Usage

import "github.com/hrygo/hotplex/internal/config"

// Load server config
loader, err := config.NewServerLoader("configs/server.yaml", logger)
if err != nil {
    log.Fatal(err)
}

// Get current config
cfg := loader.Get()

// Hot-reload support
loader.Watch(ctx, func(newCfg *ServerConfig) {
    log.Info("Config reloaded")
})

Features

  • YAML Parsing: Uses gopkg.in/yaml.v3
  • Hot-Reload: Watch for config file changes
  • Thread-Safe: Safe concurrent access via sync.RWMutex
  • Validation: Validates configuration values on load

Files

File Purpose
server_config.go Server configuration types and loader
hotreload_yaml.go YAML file watcher for hot-reload

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResolveConfigPath added in v0.24.2

func ResolveConfigPath(explicitPath string) string

ResolveConfigPath resolves the config file path from various sources. Search order: 1. Explicit path passed as argument 2. HOTPLEX_SERVER_CONFIG environment variable 3. XDG standard config directory (~/.config/hotplex/server.yaml) 4. Current working directory (./configs/server.yaml) 5. Project root fallback (../configs/server.yaml)

Types

type EngineConfig added in v0.24.2

type EngineConfig struct {
	Timeout         time.Duration `yaml:"timeout"`
	IdleTimeout     time.Duration `yaml:"idle_timeout"`
	WorkDir         string        `yaml:"work_dir"`
	SystemPrompt    string        `yaml:"system_prompt"`
	AllowedTools    []string      `yaml:"allowed_tools"`
	DisallowedTools []string      `yaml:"disallowed_tools"`
}

EngineConfig contains engine-level configuration.

type SecurityConfig added in v0.24.2

type SecurityConfig struct {
	APIKey         string `yaml:"api_key"`
	PermissionMode string `yaml:"permission_mode"`
}

SecurityConfig contains security settings.

type ServerConfig added in v0.24.2

type ServerConfig struct {
	Engine   EngineConfig   `yaml:"engine"`
	Server   ServerSettings `yaml:"server"`
	Security SecurityConfig `yaml:"security"`
}

ServerConfig represents the YAML configuration for the hotplexd server.

type ServerLoader added in v0.24.2

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

ServerLoader loads and manages server configuration from YAML files.

func NewServerLoader added in v0.24.2

func NewServerLoader(configPath string, logger *slog.Logger) (*ServerLoader, error)

NewServerLoader creates a new server configuration loader.

func (*ServerLoader) Get added in v0.24.2

func (l *ServerLoader) Get() *ServerConfig

Get returns the current server configuration.

func (*ServerLoader) GetIdleTimeout added in v0.24.2

func (l *ServerLoader) GetIdleTimeout() time.Duration

GetIdleTimeout returns the idle timeout.

func (*ServerLoader) GetPort added in v0.24.2

func (l *ServerLoader) GetPort() string

GetPort returns the server port.

func (*ServerLoader) GetSystemPrompt added in v0.24.2

func (l *ServerLoader) GetSystemPrompt() string

GetSystemPrompt returns the base system prompt.

func (*ServerLoader) GetTimeout added in v0.24.2

func (l *ServerLoader) GetTimeout() time.Duration

GetTimeout returns the engine timeout.

func (*ServerLoader) GetWorkDir added in v0.24.2

func (l *ServerLoader) GetWorkDir() string

GetWorkDir returns the working directory.

func (*ServerLoader) Load added in v0.24.2

func (l *ServerLoader) Load() error

Load loads the server configuration from the YAML file.

type ServerSettings added in v0.24.2

type ServerSettings struct {
	Port      string `yaml:"port"`
	LogLevel  string `yaml:"log_level"`
	LogFormat string `yaml:"log_format"`
}

ServerSettings contains server-level settings.

type YAMLHotReloader

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

YAMLHotReloader is a hot reload implementation for YAML configuration files. It watches for file changes and automatically reloads the configuration.

func NewYAMLHotReloader

func NewYAMLHotReloader(path string, initialConfig any, logger *slog.Logger) (*YAMLHotReloader, error)

NewYAMLHotReloader creates a new YAML hot reloader. The initialConfig must be a pointer to a struct that will be unmarshaled from YAML.

func (*YAMLHotReloader) Close

func (h *YAMLHotReloader) Close() error

Close stops the file watcher and releases resources.

func (*YAMLHotReloader) Get

func (h *YAMLHotReloader) Get() any

Get returns the current configuration.

func (*YAMLHotReloader) OnReload

func (h *YAMLHotReloader) OnReload(fn func(any))

OnReload sets the callback function that will be called when the config is reloaded.

func (*YAMLHotReloader) Start

func (h *YAMLHotReloader) Start(ctx context.Context) error

Start begins watching the configuration file for changes. It is idempotent - calling Start multiple times has no additional effect.

Jump to

Keyboard shortcuts

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