refactor(spec): move some type specs from emqx_config_handler to emqx_config
This commit is contained in:
parent
d3722ea1aa
commit
a2067c3bf3
|
@ -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
|
||||
|
|
|
@ -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}).
|
||||
|
|
Loading…
Reference in New Issue