refactor: use compile switch to diff functions between ce and ee

This commit is contained in:
Zaiming (Stone) Shi 2023-02-02 14:58:50 +01:00
parent 0e299642cb
commit 85fb53dcf0
2 changed files with 25 additions and 21 deletions

View File

@ -171,12 +171,12 @@ bridge_info_examples(Method, WithMetrics) ->
ee_bridge_examples(Method)
).
-if(?EMQX_RELEASE_EDITION == ee).
ee_bridge_examples(Method) ->
try
emqx_ee_bridge:examples(Method)
catch
_:_ -> #{}
end.
emqx_ee_bridge:examples(Method).
-else.
ee_bridge_examples(_Method) -> #{}.
-endif.
info_example(Type, Method, WithMetrics) ->
maps:merge(

View File

@ -56,8 +56,8 @@ api_schema(Method) ->
EE = ee_api_schemas(Method),
hoconsc:union(Broker ++ EE).
-if(?EMQX_RELEASE_EDITION == ee).
ee_api_schemas(Method) ->
%% must ensure the app is loaded before checking if fn is defined.
ensure_loaded(emqx_ee_bridge, emqx_ee_bridge),
case erlang:function_exported(emqx_ee_bridge, api_schemas, 1) of
true -> emqx_ee_bridge:api_schemas(Method);
@ -65,13 +65,31 @@ ee_api_schemas(Method) ->
end.
ee_fields_bridges() ->
%% must ensure the app is loaded before checking if fn is defined.
ensure_loaded(emqx_ee_bridge, emqx_ee_bridge),
case erlang:function_exported(emqx_ee_bridge, fields, 1) of
true -> emqx_ee_bridge:fields(bridges);
false -> []
end.
%% must ensure the app is loaded before checking if fn is defined.
ensure_loaded(App, Mod) ->
try
_ = application:load(App),
_ = Mod:module_info(),
ok
catch
_:_ ->
ok
end.
-else.
ee_api_schemas(_) -> [].
ee_fields_bridges() -> [].
-endif.
common_bridge_fields() ->
[
{enable,
@ -194,17 +212,3 @@ status() ->
node_name() ->
{"node", mk(binary(), #{desc => ?DESC("desc_node_name"), example => "emqx@127.0.0.1"})}.
%%=================================================================================================
%% Internal fns
%%=================================================================================================
ensure_loaded(App, Mod) ->
try
_ = application:load(App),
_ = Mod:module_info(),
ok
catch
_:_ ->
ok
end.