diff options
Diffstat (limited to 'priv/templates/simpleapp_app.erl')
-rw-r--r-- | priv/templates/simpleapp_app.erl | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/priv/templates/simpleapp_app.erl b/priv/templates/simpleapp_app.erl index 1af863b..8c645ca 100644 --- a/priv/templates/simpleapp_app.erl +++ b/priv/templates/simpleapp_app.erl @@ -1,10 +1,45 @@ +%%%------------------------------------------------------------------- +%% @copyright {{copyright_holder}} ({{copyright_year}}) +%% @author {{author_name}} <{{author_email}}> +%% @doc {{appid}} OTP application callback module. +%% @end +%%%------------------------------------------------------------------- + -module({{appid}}_app). -behaviour(application). +-define(APP, {{appid}}). + %% Application callbacks -export([start/2, stop/1]). +-export([config/0, config/1, config/2, + start/0]). + +%%%=================================================================== +%%% Convenience Functions +%%%=================================================================== + +start() -> + application:ensure_all_started(?APP, permanent). + +config(Key, Default) -> + case application:get_env(?APP, Key) of + undefined -> Default; + {ok, Val} -> Val + end. + +config(Key) -> + case application:get_env(?APP, Key) of + undefined -> erlang:error({missing_config, Key}); + {ok, Val} -> Val + end. + +config() -> + application:get_all_env(?APP). + + %% =================================================================== %% Application callbacks %% =================================================================== @@ -14,3 +49,7 @@ start(_StartType, _StartArgs) -> stop(_State) -> ok. + +%%%=================================================================== +%%% Internal functions +%%%=================================================================== |