fix(emqx_autn_api): wo do not need fixpoint

This commit is contained in:
EMQ-YangM 2022-03-11 14:04:18 +08:00
parent 7165fbc5ca
commit 8af7131a49
4 changed files with 11 additions and 15 deletions

View File

@ -224,3 +224,4 @@ error_type_two_maps(M1, M2) when is_map(M1) ->
{badmap, M2}; {badmap, M2};
error_type_two_maps(M1, _M2) -> error_type_two_maps(M1, _M2) ->
{badmap, M1}. {badmap, M1}.

View File

@ -820,14 +820,11 @@ aggregate_status(AllStatus) ->
aggregate_metrics([]) -> error_some_strange_happen; aggregate_metrics([]) -> error_some_strange_happen;
aggregate_metrics([HeadMetrics | AllMetrics]) -> aggregate_metrics([HeadMetrics | AllMetrics]) ->
CombinerFun = CombinerFun =
%% use fixpoint reference self fun ComFun(Val1, Val2) ->
fun (FixVal) ->
fun (_, Val1, Val2) ->
case erlang:is_map(Val1) of case erlang:is_map(Val1) of
true -> emqx_map_lib:merge_with(FixVal(FixVal), Val1, Val2); true -> emqx_map_lib:merge_with(ComFun, Val1, Val2);
false -> Val1 + Val2 false -> Val1 + Val2
end end
end
end, end,
Fun = fun (ElemMap, AccMap) -> Fun = fun (ElemMap, AccMap) ->
emqx_map_lib:merge_with(CombinerFun(CombinerFun), ElemMap, AccMap) end, emqx_map_lib:merge_with(CombinerFun(CombinerFun), ElemMap, AccMap) end,

View File

@ -35,3 +35,4 @@ introduced_in() ->
emqx_rpc:erpc_multicall(). emqx_rpc:erpc_multicall().
lookup_from_all_nodes(Nodes, ChainName, AuthenticatorID) -> lookup_from_all_nodes(Nodes, ChainName, AuthenticatorID) ->
erpc:multicall(Nodes, emqx_authn_api, lookup_from_local_node, [ChainName, AuthenticatorID], ?TIMEOUT). erpc:multicall(Nodes, emqx_authn_api, lookup_from_local_node, [ChainName, AuthenticatorID], ?TIMEOUT).

View File

@ -169,16 +169,13 @@ test_authenticator(PathPrefix) ->
uri(PathPrefix ++ [?CONF_NS, "password-based:http"])), uri(PathPrefix ++ [?CONF_NS, "password-based:http"])),
{ok, RList} = emqx_json:safe_decode(Res), {ok, RList} = emqx_json:safe_decode(Res),
Snd = fun ({_, Val}) -> Val end, Snd = fun ({_, Val}) -> Val end,
LookupVal = LookupVal = fun LookupV(List, RestJson) ->
fun(FixVal) ->
fun(List, RestJson) ->
case List of case List of
[Name] -> Snd(lists:keyfind(Name, 1, RestJson)); [Name] -> Snd(lists:keyfind(Name, 1, RestJson));
[Name | NS] -> (FixVal(FixVal))(NS, Snd(lists:keyfind(Name, 1, RestJson))) [Name | NS] -> LookupV(NS, Snd(lists:keyfind(Name, 1, RestJson)))
end
end end
end, end,
LookFun = fun (List) -> (LookupVal(LookupVal))(List, RList) end, LookFun = fun (List) -> LookupVal(List, RList) end,
MetricsList = [{<<"failed">>, 0}, MetricsList = [{<<"failed">>, 0},
{<<"matched">>, 0}, {<<"matched">>, 0},
{<<"rate">>, 0.0}, {<<"rate">>, 0.0},