osmo_util: introduce convenience wrappers around application:get_env()

This commit is contained in:
Harald Welte 2013-09-08 21:32:32 +02:00
parent fe6ef13a9a
commit bd88eb1b41
1 changed files with 18 additions and 0 deletions

View File

@ -40,6 +40,7 @@
-export([make_prim/4, make_prim/3]).
-export([pointcode2int/1, pointcode2int/2, pointcode_fmt/2]).
-export([asn_val/1]).
-export([get_env/2, get_env/3]).
-include("osmo_util.hrl").
@ -202,3 +203,20 @@ asn_val([]) ->
asn1_NOVALUE;
asn_val(Foo) ->
Foo.
% wrapper around application:get_env() thwowing exception on undef
get_env(App, Var) when is_atom(App), is_atom(Var) ->
case application:get_env(App, Var) of
undefined ->
throw(undefined);
{ok, Value} ->
Value
end.
get_env(App, Var, Default) ->
case application:get_env(App, Var) of
undefined ->
Default;
{ok, Value} ->
Value
end.