kvconf

GitHub Actions workflowGitHub tagLicense

rebar.conf

{deps, [{kvconf, "2024.3.1"}]}.

設定ファイル例

etc/app.conf
# コメント
key = value

設定定義例

[
    #kvc{key = a, type = #kvc_atom{candidates = [x,y,z]}, default = x},
    #kvc{key = b, type = #kvc_string{}, required = true},
    #kvc{key = c, type = #kvc_interval{min = {10, s}, max = {30, s}, out_time_unit = millisecond}, default = {20, s}},
    #kvc{key = d, type = #kvc_integer{min = 10, max = 100}},
    #kvc{key = e, type = #kvc_boolean{}, default = true}
]

環境変数による上書き

オプションで env_prefix が指定されている場合、 環境変数が設定されている場合、INI ファイルの値より優先されます。

env_prefix<<"">> は指定できません、必ず 1 バイト以上のバイナリ文字列ある必要があります。

変換ルール

使用例

%% INI ファイル (app.conf)
%% port = 3000

%% 環境変数 SPAM_PORT=8080 を設定
os:putenv("SPAM_PORT", "8080"),

%% 環境変数の値 8080 が優先される
{ok, _UnknownKeys, _UndocKvList} = kvconf:initialize([
    #kvc{key = port, type = #kvc_port_number{}, required = true}
], Binary, #{env_preifx => <<"SPAM">>}),
8080 = kvconf:get_value(port).

ライセンス

Copyright 2019-2025, Shiguredo Inc.
Copyright 2019-2021, Shunichi Shinohara (Original Author)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.