summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2013-09-08 21:32:32 +0200
committerHarald Welte <laforge@gnumonks.org>2013-09-08 21:32:32 +0200
commitbd88eb1b41b69612831fb9cd80fede70fb194929 (patch)
treedccbaa27d7894ebcc21969559acf3aad3846ecec /src
parentfe6ef13a9a90ccb6b6e1a5bbcac451696394ca42 (diff)
osmo_util: introduce convenience wrappers around application:get_env()
Diffstat (limited to 'src')
-rw-r--r--src/osmo_util.erl18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/osmo_util.erl b/src/osmo_util.erl
index d4fb5b0..f2fb1cc 100644
--- a/src/osmo_util.erl
+++ b/src/osmo_util.erl
@@ -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.