Skip to content

Add generic configuration extension mechanism #500

@diyor28

Description

@diyor28

Problem

Projects using IOTA SDK need to register custom configuration sections that load from environment variables. Currently each project implements its own config loading logic, leading to:

  • Duplicated helper functions (getEnvOrDefault, getEnvIntOrDefault)
  • Inconsistent configuration patterns across projects
  • No unified way to extend the SDK's configuration system

Use Case

shy-eld's Shyona module has agent configuration that needs to be loaded from environment variables. Currently this is duplicated between:

  • modules/shyona/config.go - module config
  • cmd/shyona-test/config.go - CLI config

Proposed Solution

Add a generic config extension mechanism using Go generics:

// ConfigExtension defines a configuration section that can be registered
type ConfigExtension interface {
    Prefix() string // e.g., "OPENAI_", "AGENTS_"
    Validate() error
}

// RegisterConfigExtension registers and loads a custom config section
func RegisterConfigExtension[T ConfigExtension](cfg *Configuration) (*T, error)

// Example usage:
type OpenAIConfig struct {
    APIKey    string
    Model     string
    MaxTokens int
}

func (c OpenAIConfig) Prefix() string { return "OPENAI_" }
func (c OpenAIConfig) Validate() error { /* ... */ }

// In application setup:
openaiCfg, err := configuration.RegisterConfigExtension[OpenAIConfig](cfg)

Acceptance Criteria

  • Generic RegisterConfigExtension function that loads env vars based on prefix
  • Support for common types (string, int, bool, duration)
  • Validation hook for custom validation logic
  • Documentation with usage examples
  • No breaking changes to existing configuration

Related

  • shy-eld#505

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions