Skip to content

Configuration

龙卷锋 edited this page Apr 16, 2020 · 21 revisions

Get config item value

1. General framework configuration file

config/application.conf

# Upload
upload.path = attachments/
upload.maxSize = 4096000
import hunt.framework.Simplify;

long uploadMaxSize = config().upload.maxSize;

More item value reference file ApplicationConfig.d


2. Custom configuration file

step1: configuration file

The custom test.conf file is in the config/ directory

setting.welcome= hello

step2: configuration mapping

The custom TestConfig.d file is in the source/app/config/ directory

module app.config.TestConfig;

import hunt.util.Configuration;

@ConfigurationFile("test") // Consistent with conf file name
class TestConfig
{
    SettingConfig setting;
}

struct SettingConfig
{
    string welcome;
}

step3 : how to use

import hunt.framework.Simplify;
import app.config.TestConfig;

auto testConfig = configManager().load!TestConfig();
string welcome = testConfig.setting.welcome;
Clone this wiki locally