config

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Challenges []*domain.Challenge `json:"challenges"`
}

Config represents the top-level configuration loaded from challenges.json. This structure is parsed from JSON and validated during application startup.

type ConfigLoader

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

ConfigLoader loads and validates challenge configuration from a JSON file. It performs file reading, JSON parsing, and comprehensive validation.

func NewConfigLoader

func NewConfigLoader(configPath string, logger *slog.Logger) *ConfigLoader

NewConfigLoader creates a new ConfigLoader instance.

Parameters:

  • configPath: Path to the challenges.json file
  • logger: Structured logger for operational logging

func (*ConfigLoader) LoadConfig

func (l *ConfigLoader) LoadConfig() (*Config, error)

LoadConfig loads the configuration file and returns a validated Config. This method performs three steps: 1. Read the config file from disk 2. Parse JSON into Config struct 3. Validate all business rules

If any step fails, returns an error and the application should exit. This is a "fail fast" operation - invalid config prevents startup.

Returns:

  • *Config: Valid configuration ready for use
  • error: Descriptive error if loading or validation fails

type Validator

type Validator struct{}

Validator validates challenge configuration files. It ensures all business rules are met before the application starts.

func NewValidator

func NewValidator() *Validator

NewValidator creates a new Validator instance.

func (*Validator) Validate

func (v *Validator) Validate(config *Config) error

Validate performs comprehensive validation of the configuration. It checks for: - At least one challenge exists - All challenge IDs are unique - All goal IDs are globally unique - All prerequisites reference valid goals - All requirements and rewards are valid

Returns an error describing the first validation failure encountered.

Jump to

Keyboard shortcuts

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