Documentation
ΒΆ
Overview ΒΆ
Package luaconfig provides a production-ready Lua configuration system for Go
Index ΒΆ
- type CLIConfig
- type CLIConfigOptions
- type Config
- func (c *Config) Call(funcName string, args ...interface{}) ([]interface{}, error)
- func (c *Config) Close()
- func (c *Config) DoFile(filename string) error
- func (c *Config) DoString(script string) error
- func (c *Config) Eval(expr string) (interface{}, error)
- func (c *Config) GenerateDocs(v interface{}, gen DocGenerator) (string, error)
- func (c *Config) Get(ctx context.Context, name string, target interface{}) error
- func (c *Config) GetGlobal(name string, target interface{}) error
- func (c *Config) LoadDirectory(dir string) error
- func (c *Config) LoadFile(ctx context.Context, filename string) error
- func (c *Config) NewCLIConfig(opts CLIConfigOptions) *CLIConfig
- func (c *Config) NewEnvManager(configDir string) *EnvManager
- func (c *Config) NewPluginManager(pcfg PluginConfig) *PluginManager
- func (c *Config) NewWatcher(wcfg WatcherConfig) (*ConfigWatcher, error)
- func (c *Config) ProcessTemplate(filename string, tcfg TemplateConfig) error
- func (c *Config) RegisterConstants(constants map[string]interface{}) error
- func (c *Config) RegisterFunction(ctx context.Context, name string, fn interface{}) error
- func (c *Config) RegisterHook(hookType HookType, hook Hook)
- func (c *Config) RegisterType(ctx context.Context, name string, typeStruct interface{}, ...) error
- func (c *Config) SetGlobal(name string, value interface{}) error
- type ConfigWatcher
- type DocGenerator
- type EnvManager
- type Environment
- type Error
- type ErrorCode
- type EventHandler
- type Generator
- func (g *Generator) Array(values ...interface{}) *Generator
- func (g *Generator) Comment(text string) *Generator
- func (g *Generator) EndFunction() *Generator
- func (g *Generator) EndTable() *Generator
- func (g *Generator) Field(name string, value interface{}) *Generator
- func (g *Generator) Function(name string, params ...string) *Generator
- func (g *Generator) Raw(code string) *Generator
- func (g *Generator) Reset()
- func (g *Generator) String() string
- func (g *Generator) Table(name string) *Generator
- type Hook
- type HookEvent
- type HookType
- type LuaFunction
- type Middleware
- type Option
- type Plugin
- type PluginAPI
- type PluginConfig
- type PluginManager
- func (pm *PluginManager) CallPluginFunction(ctx context.Context, pluginName, funcName string, args ...interface{}) (interface{}, error)
- func (pm *PluginManager) EmitEvent(ctx context.Context, event string, data interface{}) error
- func (pm *PluginManager) GetPlugin(name string) (*Plugin, bool)
- func (pm *PluginManager) LoadPlugins(ctx context.Context, dir string) error
- func (pm *PluginManager) RegisterEventHandler(event string, handler EventHandler)
- type Sandbox
- type SchemaValidator
- func (sv *SchemaValidator) AddCustomValidator(field string, validator func(interface{}) error)
- func (sv *SchemaValidator) AddNestedValidator(field string, validator *SchemaValidator)
- func (sv *SchemaValidator) AddPattern(field, pattern string) error
- func (sv *SchemaValidator) AddRange(field string, min, max float64)
- func (sv *SchemaValidator) Validate(cfg interface{}) error
- type TemplateConfig
- type WatcherConfig
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
This section is empty.
Types ΒΆ
type CLIConfig ΒΆ
type CLIConfig struct {
// contains filtered or unexported fields
}
CLIConfig represents CLI-specific configuration
func (*CLIConfig) LoadPlugins ΒΆ
LoadPlugins loads all plugins from the plugin directory
type CLIConfigOptions ΒΆ
CLIConfigOptions holds options for CLI configuration
type Config ΒΆ
Config represents the configuration manager
func (*Config) GenerateDocs ΒΆ
func (c *Config) GenerateDocs(v interface{}, gen DocGenerator) (string, error)
func (*Config) LoadDirectory ΒΆ
LoadDirectory loads all .lua files from a directory
func (*Config) NewCLIConfig ΒΆ
func (c *Config) NewCLIConfig(opts CLIConfigOptions) *CLIConfig
NewCLIConfig creates a new CLI configuration
func (*Config) NewEnvManager ΒΆ
func (c *Config) NewEnvManager(configDir string) *EnvManager
NewEnvManager creates a new environment manager
func (*Config) NewPluginManager ΒΆ
func (c *Config) NewPluginManager(pcfg PluginConfig) *PluginManager
NewPluginManager creates a new plugin manager
func (*Config) NewWatcher ΒΆ
func (c *Config) NewWatcher(wcfg WatcherConfig) (*ConfigWatcher, error)
NewWatcher creates a new configuration watcher
func (*Config) ProcessTemplate ΒΆ
func (c *Config) ProcessTemplate(filename string, tcfg TemplateConfig) error
ProcessTemplate processes a Lua configuration file as a template
func (*Config) RegisterConstants ΒΆ
RegisterConstants registers multiple constants at once
func (*Config) RegisterFunction ΒΆ
RegisterFunction registers a Go function in the Lua environment with middlewares
func (*Config) RegisterHook ΒΆ
RegisterHook registers a hook for a specific point
type ConfigWatcher ΒΆ
type ConfigWatcher struct {
// contains filtered or unexported fields
}
ConfigWatcher watches for configuration changes and reloads automatically
func (*ConfigWatcher) AddPath ΒΆ
func (w *ConfigWatcher) AddPath(path string) error
AddPath adds a path to watch
func (*ConfigWatcher) Close ΒΆ
func (w *ConfigWatcher) Close() error
Close stops watching for changes
func (*ConfigWatcher) RemovePath ΒΆ
func (w *ConfigWatcher) RemovePath(path string) error
RemovePath removes a path from watching
type DocGenerator ΒΆ
type EnvManager ΒΆ
type EnvManager struct {
// contains filtered or unexported fields
}
EnvManager manages different configuration environments
func (*EnvManager) ActivateEnvironment ΒΆ
func (em *EnvManager) ActivateEnvironment(name string) error
ActivateEnvironment activates a specific environment
func (*EnvManager) GetActiveEnvironment ΒΆ
func (em *EnvManager) GetActiveEnvironment() string
GetActiveEnvironment returns the currently active environment
func (*EnvManager) RegisterEnvironment ΒΆ
func (em *EnvManager) RegisterEnvironment(env *Environment) error
RegisterEnvironment registers a new environment
type Environment ΒΆ
type Environment struct {
// Name of the environment
Name string
// Base configuration that applies to all environments
BaseConfig string
// Environment-specific configuration
EnvConfig string
// Environment variables prefix for this environment
EnvPrefix string
// Additional configuration paths
IncludePaths []string
}
Environment represents a configuration environment (e.g., dev, staging, prod)
type EventHandler ΒΆ
EventHandler represents a function that handles plugin events
type Generator ΒΆ
type Generator struct {
// contains filtered or unexported fields
}
Generator provides a fluent API for generating Lua code
func (*Generator) EndFunction ΒΆ
EndFunction closes a function declaration
type HookEvent ΒΆ
type HookEvent struct {
Type HookType
Name string
Args []interface{}
Result interface{}
Error error
Elapsed time.Duration
}
HookEvent contains information about the hook execution
type LuaFunction ΒΆ
LuaFunction represents a function that can be called from Lua
type Middleware ΒΆ
type Middleware func(next LuaFunction) LuaFunction
Middleware represents a function that can modify behavior
type Option ΒΆ
type Option func(*Config)
Option represents a configuration option
func WithMiddleware ΒΆ
func WithMiddleware(middleware Middleware) Option
WithMiddleware adds middleware
type Plugin ΒΆ
type Plugin struct {
Name string
Version string
Description string
Path string
Exports map[string]interface{}
State *lua.LState
}
Plugin represents a loaded plugin
type PluginAPI ΒΆ
type PluginAPI interface {
// RegisterFunction registers a function that can be called from Lua
RegisterFunction(name string, fn interface{}) error
// RegisterHook registers a hook that will be called at specific points
RegisterHook(hookType HookType, hook Hook) error
// GetConfig returns the current configuration
GetConfig() *Config
// EmitEvent emits an event that other plugins can listen to
EmitEvent(name string, data interface{}) error
}
PluginAPI represents the interface that plugins can use to interact with the host application
type PluginConfig ΒΆ
type PluginConfig struct {
// Directory containing plugins
PluginDir string
// Plugin-specific sandbox settings
Sandbox *Sandbox
// Custom API implementation
API PluginAPI
// Allowed plugin types (e.g., "lua", "so")
AllowedTypes []string
// Plugin metadata requirements
RequiredMetadata []string
}
PluginConfig holds configuration for plugin loading
type PluginManager ΒΆ
type PluginManager struct {
// contains filtered or unexported fields
}
PluginManager handles plugin loading and lifecycle
func (*PluginManager) CallPluginFunction ΒΆ
func (pm *PluginManager) CallPluginFunction(ctx context.Context, pluginName, funcName string, args ...interface{}) (interface{}, error)
CallPluginFunction calls an exported plugin function
func (*PluginManager) EmitEvent ΒΆ
func (pm *PluginManager) EmitEvent(ctx context.Context, event string, data interface{}) error
EmitEvent emits an event to all registered handlers
func (*PluginManager) GetPlugin ΒΆ
func (pm *PluginManager) GetPlugin(name string) (*Plugin, bool)
GetPlugin returns a loaded plugin by name
func (*PluginManager) LoadPlugins ΒΆ
func (pm *PluginManager) LoadPlugins(ctx context.Context, dir string) error
LoadPlugins loads all plugins from the configured directory
func (*PluginManager) RegisterEventHandler ΒΆ
func (pm *PluginManager) RegisterEventHandler(event string, handler EventHandler)
RegisterEventHandler registers a handler for plugin events
type Sandbox ΒΆ
type Sandbox struct {
EnableFileIO bool
EnableNetworking bool
EnableSyscalls bool
MaxMemory uint64 // in bytes
MaxExecutionTime time.Duration
AllowedPaths []string
BlockedPaths []string
}
Sandbox provides security restrictions
type SchemaValidator ΒΆ
type SchemaValidator struct {
// Required fields
Required []string
// Pattern matching for string fields
Patterns map[string]*regexp.Regexp
// Range validation for numeric fields
Ranges map[string]struct {
Min, Max float64
}
// Custom validation functions
CustomValidators map[string]func(interface{}) error
// Nested validators for complex types
Nested map[string]*SchemaValidator
}
SchemaValidator defines validation rules for configuration
func NewSchemaValidator ΒΆ
func NewSchemaValidator() *SchemaValidator
NewSchemaValidator creates a new schema validator
func (*SchemaValidator) AddCustomValidator ΒΆ
func (sv *SchemaValidator) AddCustomValidator(field string, validator func(interface{}) error)
AddCustomValidator adds a custom validation function for a field
func (*SchemaValidator) AddNestedValidator ΒΆ
func (sv *SchemaValidator) AddNestedValidator(field string, validator *SchemaValidator)
AddNestedValidator adds a validator for nested structures
func (*SchemaValidator) AddPattern ΒΆ
func (sv *SchemaValidator) AddPattern(field, pattern string) error
AddPattern adds a regex pattern validation for a field
func (*SchemaValidator) AddRange ΒΆ
func (sv *SchemaValidator) AddRange(field string, min, max float64)
AddRange adds numeric range validation for a field
func (*SchemaValidator) Validate ΒΆ
func (sv *SchemaValidator) Validate(cfg interface{}) error
Validate validates a configuration against the schema
type TemplateConfig ΒΆ
type TemplateConfig struct {
Variables map[string]interface{}
Functions template.FuncMap
LeftDelim string
RightDelim string
}
TemplateConfig holds configuration for template processing
type WatcherConfig ΒΆ
type WatcherConfig struct {
// Paths to watch for changes
Paths []string
// How often to poll for changes (for non-inotify systems)
PollInterval time.Duration
// Debounce period to avoid multiple reloads
DebounceInterval time.Duration
// Callback function when configuration is reloaded
OnReload func(error)
}
WatcherConfig contains settings for the configuration watcher
Source Files
ΒΆ
Directories
ΒΆ
| Path | Synopsis |
|---|---|
|
_examples
|
|
|
advanced
command
|
|
|
basic
command
|
|
|
middleware
command
|
|
|
templates
command
|
|
|
validation
command
|
|
|
watcher
command
|