refactor: less copy-paste
This commit is contained in:
parent
f6dafc20ea
commit
b0ac924ca9
|
@ -1815,16 +1815,12 @@ desc(_) ->
|
||||||
%% utils
|
%% utils
|
||||||
-spec conf_get(string() | [string()], hocon:config()) -> term().
|
-spec conf_get(string() | [string()], hocon:config()) -> term().
|
||||||
conf_get(Key, Conf) ->
|
conf_get(Key, Conf) ->
|
||||||
V = hocon_maps:get(Key, Conf),
|
ensure_list(hocon_maps:get(Key, Conf)).
|
||||||
case is_binary(V) of
|
|
||||||
true ->
|
|
||||||
binary_to_list(V);
|
|
||||||
false ->
|
|
||||||
V
|
|
||||||
end.
|
|
||||||
|
|
||||||
conf_get(Key, Conf, Default) ->
|
conf_get(Key, Conf, Default) ->
|
||||||
V = hocon_maps:get(Key, Conf, Default),
|
ensure_list(hocon_maps:get(Key, Conf, Default)).
|
||||||
|
|
||||||
|
ensure_list(V) ->
|
||||||
case is_binary(V) of
|
case is_binary(V) of
|
||||||
true ->
|
true ->
|
||||||
binary_to_list(V);
|
binary_to_list(V);
|
||||||
|
|
|
@ -1308,11 +1308,9 @@ crash_dump_file_default() ->
|
||||||
|
|
||||||
%% utils
|
%% utils
|
||||||
-spec conf_get(string() | [string()], hocon:config()) -> term().
|
-spec conf_get(string() | [string()], hocon:config()) -> term().
|
||||||
conf_get(Key, Conf) ->
|
conf_get(Key, Conf) -> emqx_schema:conf_get(Key, Conf).
|
||||||
ensure_list(hocon_maps:get(Key, Conf)).
|
|
||||||
|
|
||||||
conf_get(Key, Conf, Default) ->
|
conf_get(Key, Conf, Default) -> emqx_schema:conf_get(Key, Conf, Default).
|
||||||
ensure_list(hocon_maps:get(Key, Conf, Default)).
|
|
||||||
|
|
||||||
filter(Opts) ->
|
filter(Opts) ->
|
||||||
[{K, V} || {K, V} <- Opts, V =/= undefined].
|
[{K, V} || {K, V} <- Opts, V =/= undefined].
|
||||||
|
@ -1376,15 +1374,6 @@ to_atom(Str) when is_list(Str) ->
|
||||||
to_atom(Bin) when is_binary(Bin) ->
|
to_atom(Bin) when is_binary(Bin) ->
|
||||||
binary_to_atom(Bin, utf8).
|
binary_to_atom(Bin, utf8).
|
||||||
|
|
||||||
-spec ensure_list(binary() | list(char())) -> list(char()).
|
|
||||||
ensure_list(V) ->
|
|
||||||
case is_binary(V) of
|
|
||||||
true ->
|
|
||||||
binary_to_list(V);
|
|
||||||
false ->
|
|
||||||
V
|
|
||||||
end.
|
|
||||||
|
|
||||||
roots(Module) ->
|
roots(Module) ->
|
||||||
lists:map(fun({_BinName, Root}) -> Root end, hocon_schema:roots(Module)).
|
lists:map(fun({_BinName, Root}) -> Root end, hocon_schema:roots(Module)).
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue