移除掉jiffy的依赖
This commit is contained in:
parent
050cfbb662
commit
58d851a0f1
@ -26,7 +26,6 @@
|
||||
{deps, [
|
||||
{poolboy, ".*", {git, "https://github.com/devinus/poolboy.git", {tag, "1.5.1"}}},
|
||||
{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"}}},
|
||||
{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"}}},
|
||||
|
||||
@ -66,7 +66,7 @@ parse_body(Req0) ->
|
||||
{ok, Body, Req1} = read_body(Req0),
|
||||
case Body /= <<>> of
|
||||
true ->
|
||||
{ok, catch jiffy:decode(Body, [return_maps]), Req1};
|
||||
{ok, catch json:decode(Body), Req1};
|
||||
false ->
|
||||
{ok, #{}, Req1}
|
||||
end;
|
||||
|
||||
@ -60,7 +60,7 @@ handle_command([<<"PING">>]) ->
|
||||
{reply, encode({single_line, <<"PONG">>})};
|
||||
|
||||
handle_command([<<"PUBLISH">>, _Channel, Msg]) ->
|
||||
case catch jiffy:decode(Msg, [return_maps]) of
|
||||
case catch json:decode(Msg) of
|
||||
M when is_map(M) ->
|
||||
handle_data(M);
|
||||
_ ->
|
||||
|
||||
@ -10,7 +10,6 @@
|
||||
ranch,
|
||||
poolboy,
|
||||
mysql,
|
||||
jiffy,
|
||||
hackney,
|
||||
throttle,
|
||||
dns_erlang,
|
||||
|
||||
@ -121,13 +121,13 @@ safe_request(Fun) when is_function(Fun, 0) ->
|
||||
|
||||
-spec decode_json(Resp :: binary()) -> {ok, map()} | {error, any()}.
|
||||
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) ->
|
||||
{ok, Result};
|
||||
{'EXIT', Reason} ->
|
||||
{error, Reason};
|
||||
Error ->
|
||||
{error, Error}
|
||||
Other ->
|
||||
{error, {invalid_json, Other}}
|
||||
catch error:Reason ->
|
||||
{error, Reason}
|
||||
end.
|
||||
|
||||
-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)}
|
||||
],
|
||||
|
||||
Body = iolist_to_binary(jiffy:encode(Params, [force_utf8])),
|
||||
Body = iolist_to_binary(json:encode(Params)),
|
||||
Url = Url0 ++ Uri,
|
||||
|
||||
case catch hackney:request(post, Url, Headers, Body, [{pool, false}]) of
|
||||
|
||||
@ -63,11 +63,11 @@ hex0(I) -> $0 + I.
|
||||
|
||||
-spec json_data(Data :: term()) -> iodata().
|
||||
json_data(Data) ->
|
||||
jiffy:encode(#{<<"result">> => Data}, [force_utf8]).
|
||||
json:encode(#{<<"result">> => Data}).
|
||||
|
||||
-spec json_error(ErrCode :: integer(), ErrMessage :: binary()) -> iodata().
|
||||
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.
|
||||
assert_call(true, F) ->
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user