From c9a59968efb7aee200f983057298f476258a5f3c Mon Sep 17 00:00:00 2001 From: k32 <10274441+k32@users.noreply.github.com> Date: Thu, 18 Nov 2021 19:00:59 +0100 Subject: [PATCH] refactor(emqx_schema): Code style --- apps/emqx_conf/src/emqx_conf_schema.erl | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) 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)).