import tomllib import logging DEFAULT_CONFIG = { "server": { "host": "0.0.0.0", "port": 8000, }, "wireguard": { "config_file": "/etc/wireguard/wg0.conf", }, "logging": { "log_file": None, "debug": False, } } def load_config(config_file: str = "config.toml") -> dict: try: with open(config_file, "rb") as f: config = tomllib.load(f) return {**DEFAULT_CONFIG, **config} except FileNotFoundError: logging.warning(f"Config file {config_file} not found. Using default configuration.") return DEFAULT_CONFIG except tomllib.TOMLDecodeError as e: logging.error(f"Error parsing config file: {e}") exit(1)