移除掉jiffy的依赖

This commit is contained in:
anlicheng 2026-05-03 16:29:39 +08:00
parent 050cfbb662
commit 58d851a0f1
6 changed files with 10 additions and 12 deletions

View File

@ -26,7 +26,6 @@
{deps, [ {deps, [
{poolboy, ".*", {git, "https://github.com/devinus/poolboy.git", {tag, "1.5.1"}}}, {poolboy, ".*", {git, "https://github.com/devinus/poolboy.git", {tag, "1.5.1"}}},
{hackney, ".*", {git, "https://github.com/benoitc/hackney.git", {tag, "1.16.0"}}}, {hackney, ".*", {git, "https://github.com/benoitc/hackney.git", {tag, "1.16.0"}}},
{jiffy, ".*", {git, "https://github.com/davisp/jiffy.git", {tag, "1.1.1"}}},
{cowboy, ".*", {git, "https://github.com/ninenines/cowboy.git", {tag, "2.12.0"}}}, {cowboy, ".*", {git, "https://github.com/ninenines/cowboy.git", {tag, "2.12.0"}}},
{mysql, ".*", {git, "https://github.com/mysql-otp/mysql-otp", {tag, "1.8.0"}}}, {mysql, ".*", {git, "https://github.com/mysql-otp/mysql-otp", {tag, "1.8.0"}}},
{throttle, ".*", {git, "https://github.com/lambdaclass/throttle.git", {tag, "0.3.0"}}}, {throttle, ".*", {git, "https://github.com/lambdaclass/throttle.git", {tag, "0.3.0"}}},

View File

@ -66,7 +66,7 @@ parse_body(Req0) ->
{ok, Body, Req1} = read_body(Req0), {ok, Body, Req1} = read_body(Req0),
case Body /= <<>> of case Body /= <<>> of
true -> true ->
{ok, catch jiffy:decode(Body, [return_maps]), Req1}; {ok, catch json:decode(Body), Req1};
false -> false ->
{ok, #{}, Req1} {ok, #{}, Req1}
end; end;

View File

@ -60,7 +60,7 @@ handle_command([<<"PING">>]) ->
{reply, encode({single_line, <<"PONG">>})}; {reply, encode({single_line, <<"PONG">>})};
handle_command([<<"PUBLISH">>, _Channel, Msg]) -> handle_command([<<"PUBLISH">>, _Channel, Msg]) ->
case catch jiffy:decode(Msg, [return_maps]) of case catch json:decode(Msg) of
M when is_map(M) -> M when is_map(M) ->
handle_data(M); handle_data(M);
_ -> _ ->

View File

@ -10,7 +10,6 @@
ranch, ranch,
poolboy, poolboy,
mysql, mysql,
jiffy,
hackney, hackney,
throttle, throttle,
dns_erlang, dns_erlang,

View File

@ -121,13 +121,13 @@ safe_request(Fun) when is_function(Fun, 0) ->
-spec decode_json(Resp :: binary()) -> {ok, map()} | {error, any()}. -spec decode_json(Resp :: binary()) -> {ok, map()} | {error, any()}.
decode_json(Resp) when is_binary(Resp) -> decode_json(Resp) when is_binary(Resp) ->
case catch jiffy:decode(Resp, [return_maps]) of try json:decode(Resp) of
Result when is_map(Result) -> Result when is_map(Result) ->
{ok, Result}; {ok, Result};
{'EXIT', Reason} -> Other ->
{error, Reason}; {error, {invalid_json, Other}}
Error -> catch error:Reason ->
{error, Error} {error, Reason}
end. end.
-spec do_get(Uri :: string(), Params :: [{K :: binary(), V :: binary()}]) -> {ok, Response :: binary()} | {error, Reason :: any()}. -spec do_get(Uri :: string(), Params :: [{K :: binary(), V :: binary()}]) -> {ok, Response :: binary()} | {error, Reason :: any()}.
@ -165,7 +165,7 @@ do_post(Uri, Params) when is_list(Uri), is_map(Params) ->
{<<"X-sign">>, sign_params(Params)} {<<"X-sign">>, sign_params(Params)}
], ],
Body = iolist_to_binary(jiffy:encode(Params, [force_utf8])), Body = iolist_to_binary(json:encode(Params)),
Url = Url0 ++ Uri, Url = Url0 ++ Uri,
case catch hackney:request(post, Url, Headers, Body, [{pool, false}]) of case catch hackney:request(post, Url, Headers, Body, [{pool, false}]) of

View File

@ -63,11 +63,11 @@ hex0(I) -> $0 + I.
-spec json_data(Data :: term()) -> iodata(). -spec json_data(Data :: term()) -> iodata().
json_data(Data) -> json_data(Data) ->
jiffy:encode(#{<<"result">> => Data}, [force_utf8]). json:encode(#{<<"result">> => Data}).
-spec json_error(ErrCode :: integer(), ErrMessage :: binary()) -> iodata(). -spec json_error(ErrCode :: integer(), ErrMessage :: binary()) -> iodata().
json_error(ErrCode, ErrMessage) when is_integer(ErrCode), is_binary(ErrMessage) -> json_error(ErrCode, ErrMessage) when is_integer(ErrCode), is_binary(ErrMessage) ->
jiffy:encode(#{<<"error">> => #{<<"code">> => ErrCode, <<"message">> => ErrMessage}}, [force_utf8]). json:encode(#{<<"error">> => #{<<"code">> => ErrCode, <<"message">> => ErrMessage}}).
-spec assert_call(Condition :: boolean(), F :: fun(() -> T)) -> T | ok. -spec assert_call(Condition :: boolean(), F :: fun(() -> T)) -> T | ok.
assert_call(true, F) -> assert_call(true, F) ->