diff --git a/apps/emqx_conf/src/emqx_conf_schema.erl b/apps/emqx_conf/src/emqx_conf_schema.erl index cfcc12905..350ee9e3a 100644 --- a/apps/emqx_conf/src/emqx_conf_schema.erl +++ b/apps/emqx_conf/src/emqx_conf_schema.erl @@ -741,22 +741,10 @@ sort_log_levels(Levels) -> %% utils -spec(conf_get(string() | [string()], hocon:config()) -> term()). conf_get(Key, Conf) -> - V = hocon_schema:get_value(Key, Conf), - case is_binary(V) of - true -> - binary_to_list(V); - false -> - V - end. + ensure_list(hocon_schema:get_value(Key, Conf)). conf_get(Key, Conf, Default) -> - V = hocon_schema:get_value(Key, Conf, Default), - case is_binary(V) of - true -> - binary_to_list(V); - false -> - V - end. + ensure_list(hocon_schema:get_value(Key, Conf, Default)). filter(Opts) -> [{K, V} || {K, V} <- Opts, V =/= undefined]. @@ -812,5 +800,14 @@ to_atom(Str) when is_list(Str) -> to_atom(Bin) when is_binary(Bin) -> 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) -> lists:map(fun({_BinName, Root}) -> Root end, hocon_schema:roots(Module)).