您应该将应用程序属性放在钢筋erlang应用程序中? [英] Where should you put application properties in a rebar erlang application?
问题描述
一个新手问题:我写了我的第一个基于螺纹钢的erlang应用程序。我想配置一些基本的功能,如服务器主机等。放置它们的最佳位置在哪里,我应该如何将它们加载到应用程序中?
A newbie question: I wrote my first rebar based erlang application. I want to configure some basic properites like server host etc. Where is the best place to put them and how should I load them into the app?
推荐答案
接下来的步骤是发布并在其中创建一个节点。节点在独立的Erlang VM中运行应用程序。使用钢筋创建发行版的好起点:
The next steps are to make a release and create a node in it. A node runs your application in a standalone Erlang VM. A good starting point for creating a release using rebar:
创建一个版本后。您的节点中所有应用程序的配置属性可以添加到
Once you have created a release. The configuration properties for all applications in your node can then be added to
{your-app}/{release}/files/sys.config
您可以按以下方式阅读个别属性:
You can read individual properties as follows:
Val = application:get_env(APP, KEY)
或者,您的应用程序的所有属性都可以读取为
Alternatively, all properties for your application can be read as
Config = application:get_all_env(APP)
在 sys.config
中,属性可以添加为 proplist变种
。
In sys.config
, properties can be added as a proplist
.
示例:
{myapp,
[
{port, 1234},
{pool_size, 5}
]
}
这篇关于您应该将应用程序属性放在钢筋erlang应用程序中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!