From a2067c3bf39ada686ff4bda9fb3e351cba14790c Mon Sep 17 00:00:00 2001 From: Shawn <506895667@qq.com> Date: Tue, 17 Aug 2021 10:48:29 +0800 Subject: [PATCH] refactor(spec): move some type specs from emqx_config_handler to emqx_config --- apps/emqx/src/emqx_config.erl | 17 +++++++++++++---- apps/emqx/src/emqx_config_handler.erl | 9 +-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/apps/emqx/src/emqx_config.erl b/apps/emqx/src/emqx_config.erl index cff511352..a86d4b309 100644 --- a/apps/emqx/src/emqx_config.erl +++ b/apps/emqx/src/emqx_config.erl @@ -88,8 +88,17 @@ error:badarg -> EXP_ON_FAIL end). --export_type([update_request/0, raw_config/0, config/0]). +-export_type([update_request/0, raw_config/0, config/0, + update_opts/0, update_cmd/0, update_args/0]). + -type update_request() :: term(). +-type update_cmd() :: {update, update_request()} | remove. +-type update_opts() :: #{ + %% fill the default values into the rawconf map + rawconf_with_defaults => boolean() + }. +-type update_args() :: {update_cmd(), Opts :: update_opts()}. + %% raw_config() is the config that is NOT parsed and tranlated by hocon schema -type raw_config() :: #{binary() => term()} | undefined. %% config() is the config that is parsed and tranlated by hocon schema @@ -188,7 +197,7 @@ update(KeyPath, UpdateReq) -> update(KeyPath, UpdateReq, #{}). -spec update(emqx_map_lib:config_key_path(), update_request(), - emqx_config_handler:update_opts()) -> + update_opts()) -> {ok, config(), raw_config()} | {error, term()}. update([RootName | _] = KeyPath, UpdateReq, Opts) -> emqx_config_handler:update_config(get_schema_mod(RootName), KeyPath, @@ -198,12 +207,12 @@ update([RootName | _] = KeyPath, UpdateReq, Opts) -> remove(KeyPath) -> remove(KeyPath, #{}). --spec remove(emqx_map_lib:config_key_path(), emqx_config_handler:update_opts()) -> +-spec remove(emqx_map_lib:config_key_path(), update_opts()) -> ok | {error, term()}. remove([RootName | _] = KeyPath, Opts) -> emqx_config_handler:update_config(get_schema_mod(RootName), KeyPath, {remove, Opts}). --spec reset(emqx_map_lib:config_key_path(), emqx_config_handler:update_opts()) -> +-spec reset(emqx_map_lib:config_key_path(), update_opts()) -> {ok, config(), raw_config()} | {error, term()}. reset([RootName | _] = KeyPath, Opts) -> case get_default_value(KeyPath) of diff --git a/apps/emqx/src/emqx_config_handler.erl b/apps/emqx/src/emqx_config_handler.erl index cae104945..ee03ff4ef 100644 --- a/apps/emqx/src/emqx_config_handler.erl +++ b/apps/emqx/src/emqx_config_handler.erl @@ -38,15 +38,8 @@ -define(MOD, {mod}). --export_type([update_opts/0, update_cmd/0, update_args/0]). -type handler_name() :: module(). -type handlers() :: #{emqx_config:config_key() => handlers(), ?MOD => handler_name()}. --type update_cmd() :: {update, emqx_config:update_request()} | remove. --type update_opts() :: #{ - %% fill the default values into the rawconf map - rawconf_with_defaults => boolean() - }. --type update_args() :: {update_cmd(), Opts :: update_opts()}. -optional_callbacks([ pre_config_update/2 , post_config_update/3 @@ -66,7 +59,7 @@ start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, {}, []). --spec update_config(module(), emqx_config:config_key_path(), update_args()) -> +-spec update_config(module(), emqx_config:config_key_path(), emqx_config:update_args()) -> {ok, emqx_config:config(), emqx_config:raw_config()} | {error, term()}. update_config(SchemaModule, ConfKeyPath, UpdateArgs) -> gen_server:call(?MODULE, {change_config, SchemaModule, ConfKeyPath, UpdateArgs}).