module main import toml import os const ( path = config_path() ) struct Config { host string port int token string redirect bool redirect_url string db_path string origins []string } fn (config Config) copy() Config { return config } fn load_config() !Config { if !os.is_file(path) { return error('Config file does not exist or is not a file') } config := toml.parse_file(path) or { return error('Error while parsing config file:\n' + err.msg()) } return Config{ host: config.value('host').string() port: config.value('port').int() token: config.value('token').string() redirect: config.value('redirect').bool() redirect_url: config.value('redirect_url').string() db_path: config.value('db_path').string() origins: config.value('origins').array().as_strings() } } fn config_path() string { path_env := $env('CONFIG_PATH') if path_env.trim_space().len != 0 { return path_env } return './config.toml' }