config

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: May 6, 2025 License: GPL-3.0 Imports: 4 Imported by: 0

README

internal/config

Description

The internal/config package is responsible for managing the application's configuration. It loads settings from a configuration file, validates them, and provides a structured way for other parts of the application to access these settings.

Key Components
  • Configuration Structs (config.go):

    • Defines Go structs (e.g., Config, ServerConfig, SimulationConfig, StorageConfig, PluginConfig, LogConfig, etc.) that map to the structure of the configuration file.
    • These structs hold all configurable parameters for different aspects of the LaunchRail application.
  • Loading Mechanism (config.go):

    • Utilizes the spf13/viper library to read configuration data from a YAML file (typically named config.yaml or specified via environment variables/flags).
    • Provides functions like Load() or NewConfig() to initialize and populate the configuration structs.
    • Often implements a singleton pattern or a central access point to ensure consistent configuration across the application.
  • Validation (config.go):

    • Includes logic to validate the loaded configuration. This ensures that required fields are present, values are within acceptable ranges or formats, and inter-dependencies between settings are consistent.
    • Validation might occur during the loading process or via an explicit Validate() method.
  • Testing (config_test.go):

    • Contains unit tests to verify:
      • Successful loading of valid configuration files.
      • Correct parsing of different configuration values and structures.
      • Proper handling of missing or malformed configuration files.
      • Effectiveness of validation rules (e.g., ensuring errors are reported for invalid settings).
Core Functionalities
  • Centralized Configuration: Provides a single source of truth for all application settings.
  • Type-Safe Access: Allows other packages to access configuration parameters in a type-safe manner through the defined structs.
  • Flexibility: Supports configuration via files, and potentially environment variables or command-line flags (capabilities often provided by viper).
  • Robustness: Ensures the application starts with a valid and coherent configuration through validation.
Technical Details
  • Library: spf13/viper for configuration management.
  • Format: Typically YAML, but viper can support other formats.
  • Default Location: Often expects a config.yaml in a predefined location or the working directory, but this can be overridden.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	Name    string `mapstructure:"name"`
	Version string `mapstructure:"version"`
}

App represents the application configuration.

type Atmosphere

type Atmosphere struct {
	ISAConfiguration ISAConfiguration `mapstructure:"isa_configuration"`
}

Atmosphere represents the atmosphere configuration.

type BenchmarkEntry added in v0.3.5

type BenchmarkEntry struct {
	Name             string `mapstructure:"name" validate:"required"`
	Description      string `mapstructure:"description"` // Added missing field
	DesignFile       string `mapstructure:"design_file" validate:"required,file"`
	DataDir          string `mapstructure:"data_dir" validate:"required,dir"`
	MotorDesignation string `mapstructure:"motor_designation"` // Added motor designation
	Enabled          bool   `mapstructure:"enabled" validate:"boolean"`
}

BenchmarkEntry defines the configuration for a single benchmark.

type Config

type Config struct {
	Setup      Setup                     `mapstructure:"setup"`
	Server     Server                    `mapstructure:"server"`
	Engine     Engine                    `mapstructure:"engine"`
	Benchmarks map[string]BenchmarkEntry `mapstructure:"benchmarks"`
}

Config represents the overall application configuration.

func GetConfig

func GetConfig() (*Config, error)

GetConfig reads configuration, validates it, resolves paths, and returns a new instance.

func (*Config) Bytes

func (c *Config) Bytes() []byte

Bytes returns the configuration as bytes

func (*Config) ToMap added in v0.7.0

func (c *Config) ToMap() map[string]string

ToMap converts the configuration to a map of strings.

func (*Config) Validate

func (cfg *Config) Validate(configFileDir string) error

Validate checks the configuration for errors and resolves relative paths. configFileDir is the directory containing the configuration file, used as a base for relative paths.

type Engine

type Engine struct {
	External   External   `mapstructure:"external"`
	Options    Options    `mapstructure:"options"`
	Simulation Simulation `mapstructure:"simulation"`
}

Engine represents the engine configuration (simulation specific).

type External

type External struct {
	OpenRocketVersion string `mapstructure:"openrocket_version"`
}

External represents the external configuration.

type ISAConfiguration

type ISAConfiguration struct {
	SpecificGasConstant  float64 `mapstructure:"specific_gas_constant"`
	GravitationalAccel   float64 `mapstructure:"gravitational_accel"`
	SeaLevelDensity      float64 `mapstructure:"sea_level_density"`
	SeaLevelTemperature  float64 `mapstructure:"sea_level_temperature"`
	SeaLevelPressure     float64 `mapstructure:"sea_level_pressure"`
	RatioSpecificHeats   float64 `mapstructure:"ratio_specific_heats"`
	TemperatureLapseRate float64 `mapstructure:"temperature_lapse_rate"`
}

ISAConfiguration represents the ISA configuration.

type Launchrail

type Launchrail struct {
	Length      float64 `mapstructure:"length"`
	Angle       float64 `mapstructure:"angle"`
	Orientation float64 `mapstructure:"orientation"`
}

Launchrail represents the launchrail configuration.

type Launchsite

type Launchsite struct {
	Latitude   float64    `mapstructure:"latitude"`
	Longitude  float64    `mapstructure:"longitude"`
	Altitude   float64    `mapstructure:"altitude"`
	Atmosphere Atmosphere `mapstructure:"atmosphere"`
}

Launchsite represents the launchsite configuration.

type Logging

type Logging struct {
	Level string `mapstructure:"level"`
}

Logging represents the logging configuration.

type Options

type Options struct {
	MotorDesignation string     `mapstructure:"motor_designation"`
	OpenRocketFile   string     `mapstructure:"openrocket_file"`
	Launchrail       Launchrail `mapstructure:"launchrail"`
	Launchsite       Launchsite `mapstructure:"launchsite"`
}

Options represents the application options.

type Plugins

type Plugins struct {
	Paths []string `mapstructure:"paths"`
}

Plugins represents runtime plugins to enrich the simulation

type Server

type Server struct {
	Port int `mapstructure:"port"`
}

Server represents the server configuration.

type Setup

type Setup struct {
	App     App     `mapstructure:"app"`
	Logging Logging `mapstructure:"logging"`
	Plugins Plugins `mapstructure:"plugins"`
}

Setup represents the setup configuration.

type Simulation

type Simulation struct {
	Step            float64 `mapstructure:"step"`
	MaxTime         float64 `mapstructure:"max_time"`
	GroundTolerance float64 `mapstructure:"ground_tolerance"` // Add ground tolerance
}

Simulation represents the simulation configuration.

Jump to

Keyboard shortcuts

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