如何在Erlang / OTP中使用应用程序:get_env()? [英] How to use application:get_env() in Erlang/OTP?
问题描述
我创建了一个mochiweb实例
I created a mochiweb instance
src/
|-- Makefile
|-- room.erl
|-- myserver.app
|-- myserver.erl
|-- myserver_app.erl
|-- myserver_deps.erl
|-- myserver_sup.erl
|-- myserver_web.erl
`-- uuid.erl
在 myserver_web.erl
我可以访问应用程序配置
in myserver_web.erl
I am able to access the application config
{ok, "0.0.1"} = application:get_key(vsn),
c $ c> room.erl ,我无法访问应用程序配置(特别是 env
列表)。
However in room.erl
, I am not able to access the application config (specifically the env
list).
undefined = application:get_key(vsn),
主管不启动房间,也不想要它。
The supervisor does not start the room, nor do I want it too.
我是OTP的新手,我意识到我可能会做一些愚蠢的事情,但我真的非常感谢任何人的帮助。
I'm new to OTP and I realize I'm probably doing something stupid, but I would really appreciate anyone's help.
干杯!
推荐答案
从关于应用程序的Erlang文档:get_key / 1-2功能:
返回应用程序的值
规范键应用程序的键。
如果应用程序参数为
,则默认为调用进程的
应用程序。
Returns the value of the application specification key Key for Application. If the application argument is omitted, it defaults to the application of the calling process.
my_server_web.erl的应用是什么? room.erl的应用是什么?
What's the application of my_server_web.erl? What's the application of room.erl?
如果指定的应用程序不是
加载,或规范键
不存在,或者执行
的进程不属于任何
应用程序,该函数将返回
undefined。
If the specified application is not loaded, or the specification key does not exist, or if the process executing the call does not belong to any application, the function returns undefined.
是否指定了密钥?是否加载了应用程序?
Is the key specified? Is the application loaded?
关于env键,您可以使用应用程序:get_env / 1功能。
Regarding the "env" key, you can use the application:get_env/1 function instead.
这篇关于如何在Erlang / OTP中使用应用程序:get_env()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!