在Erlang应用程序中管理配置 [英] Managing configuration in Erlang application

查看:100
本文介绍了在Erlang应用程序中管理配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过我的应用程序分发某种静态配置。

I need to distribute some sort of static configuration through my application. What is the best practice to do that?

我看到三个选项:


  1. 当模块需要获取配置值时,直接调用应用程序:get_env

    • 加上:比其他选项更简单。

    • 减号:如何测试这些模块, >
    • 减去:如何启动具有不同配置的某个模块(如果需要)?

  1. Call application:get_env directly whenever a module requires to get configuration value.
    • Plus: simpler than other options.
    • Minus: how to test such modules without bringing the whole application thing up?
    • Minus: how to start certain module with different configuration (if required)?

  • 此外:模块更容易测试,您可以使用不同的配置启动它们。

  • 减:许多样板代码。更改配置格式需要修复多个位置。


  • 加上:或多或少的类型安全审批。

  • 减号:需要在运行模块之前启动配置过程。

  • 减号:如何启动具有不同配置的某个模块(如果需要)?


推荐答案

另一种方法是将配置数据转换为Erlang源模块,通过导出使配置数据可用。然后,您可以通过简单地加载新版本的配置模块,随时在正在运行的系统中更改配置。

Another approach is to transform your configuration data into an Erlang source module that makes the configuration data available through exports. Then you can change the configuration at any time in a running system by simply loading a new version of the configuration module.

这篇关于在Erlang应用程序中管理配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆