replace json
This commit is contained in:
parent
00bb22711b
commit
6ed4c6fad3
@ -31,7 +31,6 @@
|
||||
|
||||
{deps, [
|
||||
{sync, ".*", {git, "https://github.com/rustyio/sync.git", {branch, "master"}}},
|
||||
{jiffy, ".*", {git, "https://github.com/davisp/jiffy.git", {tag, "1.1.3"}}},
|
||||
{cowboy, ".*", {git, "https://github.com/ninenines/cowboy.git", {tag, "2.10.0"}}},
|
||||
{gun, ".*", {git, "https://github.com/ninenines/gun.git", {tag, "2.2.0"}}}
|
||||
]}.
|
||||
|
||||
@ -43,7 +43,7 @@ create_container(ContainerDir, #'ContainerDeployParams'{container_name = Contain
|
||||
Options = docker_container_builder:build_options(ContainerName, ContainerDir, CreateOpts),
|
||||
display_options(Options),
|
||||
|
||||
Body = iolist_to_binary(jiffy:encode(Options, [force_utf8])),
|
||||
Body = iolist_to_binary(json:encode(Options)),
|
||||
true = is_binary(Body),
|
||||
|
||||
Headers = [
|
||||
@ -52,14 +52,14 @@ create_container(ContainerDir, #'ContainerDeployParams'{container_name = Contain
|
||||
|
||||
case docker_client:request("POST", Url, Body, Headers) of
|
||||
{ok, 201, _Headers, Resp} ->
|
||||
case catch jiffy:decode(Resp, [return_maps]) of
|
||||
case catch json:decode(Resp) of
|
||||
#{<<"Id">> := ContainerId} when is_binary(ContainerId) ->
|
||||
{ok, ContainerId};
|
||||
_ ->
|
||||
{error, Resp}
|
||||
end;
|
||||
{ok, _StatusCode, _, ErrorResp} ->
|
||||
case catch jiffy:decode(ErrorResp, [return_maps]) of
|
||||
case catch json:decode(ErrorResp) of
|
||||
#{<<"message">> := Msg} ->
|
||||
{error, Msg};
|
||||
_ ->
|
||||
@ -99,7 +99,7 @@ start_container(ContainerName) when is_binary(ContainerName) ->
|
||||
{ok, 304, _Headers, _} ->
|
||||
{error, <<"container already started">>};
|
||||
{ok, _StatusCode, _Header, ErrorResp} ->
|
||||
case catch jiffy:decode(ErrorResp, [return_maps]) of
|
||||
case catch json:decode(ErrorResp) of
|
||||
#{<<"message">> := Msg} ->
|
||||
{error, Msg};
|
||||
_ ->
|
||||
@ -125,7 +125,7 @@ stop_container(ContainerName, TimeoutSeconds) when is_binary(ContainerName), is_
|
||||
{ok, 304, _Headers, _} ->
|
||||
{error, <<"container already stopped">>};
|
||||
{ok, _StatusCode, _Header, ErrorResp} ->
|
||||
case catch jiffy:decode(ErrorResp, [return_maps]) of
|
||||
case catch json:decode(ErrorResp) of
|
||||
#{<<"message">> := Msg} ->
|
||||
{error, Msg};
|
||||
_ ->
|
||||
@ -149,7 +149,7 @@ kill_container(ContainerName, Signal) when is_binary(ContainerName), is_binary(S
|
||||
{ok, 204, _Headers, _} ->
|
||||
ok;
|
||||
{ok, _StatusCode, _Header, ErrorResp} ->
|
||||
case catch jiffy:decode(ErrorResp, [return_maps]) of
|
||||
case catch json:decode(ErrorResp) of
|
||||
#{<<"message">> := Msg} ->
|
||||
{error, Msg};
|
||||
_ ->
|
||||
@ -176,7 +176,7 @@ remove_container(ContainerName, Force, RemoveVolumes)
|
||||
{ok, 304, _Headers, _} ->
|
||||
{error, <<"container already stopped">>};
|
||||
{ok, _StatusCode, _Header, ErrorResp} ->
|
||||
case catch jiffy:decode(ErrorResp, [return_maps]) of
|
||||
case catch json:decode(ErrorResp) of
|
||||
#{<<"message">> := Msg} ->
|
||||
{error, Msg};
|
||||
_ ->
|
||||
@ -194,10 +194,10 @@ get_containers() ->
|
||||
],
|
||||
case docker_client:request("GET", Url, <<>>, Headers) of
|
||||
{ok, 200, _Headers, ContainersBin} ->
|
||||
Containers = jiffy:decode(ContainersBin, [return_maps]),
|
||||
Containers = json:decode(ContainersBin),
|
||||
{ok, Containers};
|
||||
{ok, _StatusCode, _Header, ErrorResp} ->
|
||||
case catch jiffy:decode(ErrorResp, [return_maps]) of
|
||||
case catch json:decode(ErrorResp) of
|
||||
#{<<"message">> := Msg} ->
|
||||
{error, Msg};
|
||||
_ ->
|
||||
@ -217,7 +217,7 @@ inspect_container(ContainerId) when is_binary(ContainerId) ->
|
||||
{ok, 200, _Headers, Resp} ->
|
||||
decode_container_inspect_summary(Resp);
|
||||
{ok, _StatusCode, _Header, ErrorResp} ->
|
||||
case catch jiffy:decode(ErrorResp, [return_maps]) of
|
||||
case catch json:decode(ErrorResp) of
|
||||
#{<<"message">> := Msg} ->
|
||||
{error, Msg};
|
||||
_ ->
|
||||
@ -263,7 +263,7 @@ json_state_running(Json) when is_binary(Json) ->
|
||||
|
||||
-spec display_options(Options :: map()) -> no_return().
|
||||
display_options(Options) when is_map(Options) ->
|
||||
logger:debug("deploy options: ~p", [jiffy:encode(Options, [force_utf8])]),
|
||||
logger:debug("deploy options: ~p", [iolist_to_binary(json:encode(Options))]),
|
||||
lists:foreach(fun({K, V}) -> logger:debug("~p => ~p", [K, V]) end, maps:to_list(Options)).
|
||||
|
||||
-spec build_stop_container_url(ContainerName :: binary(), TimeoutSeconds :: non_neg_integer()) -> string().
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
handle_request(#'ContainerRequest'{action = {list, #'ContainerRequest.List'{all = _All}}}) ->
|
||||
case docker_commands:get_containers() of
|
||||
{ok, Containers} ->
|
||||
{ok, jiffy:encode(Containers, [force_utf8])};
|
||||
{ok, iolist_to_binary(json:encode(Containers))};
|
||||
{error, Reason} when is_binary(Reason) ->
|
||||
{error, Reason}
|
||||
end;
|
||||
|
||||
@ -93,7 +93,7 @@ handle_info({timeout, _, attach_docker_events}, State = #state{port = undefined}
|
||||
{noreply, State}
|
||||
end;
|
||||
handle_info({Port, {data, {eol, BinLine}}}, State = #state{port = Port}) ->
|
||||
Event = catch jiffy:decode(BinLine, [return_maps]),
|
||||
Event = catch json:decode(BinLine),
|
||||
logger:debug("event: ~p", [Event]),
|
||||
handle_event(Event, State),
|
||||
{noreply, State};
|
||||
|
||||
@ -6,7 +6,6 @@
|
||||
{applications,
|
||||
[
|
||||
sync,
|
||||
jiffy,
|
||||
cowboy,
|
||||
ranch,
|
||||
crypto,
|
||||
|
||||
@ -68,18 +68,18 @@ chunks0([Hd | Tail], Size, Num, Target, AccTarget) ->
|
||||
|
||||
-spec json_data(term()) -> binary().
|
||||
json_data(Data) ->
|
||||
jiffy:encode(#{
|
||||
iolist_to_binary(json:encode(#{
|
||||
<<"result">> => Data
|
||||
}, [force_utf8]).
|
||||
})).
|
||||
|
||||
-spec json_error(integer(), binary()) -> binary().
|
||||
json_error(ErrCode, ErrMessage) when is_integer(ErrCode), is_binary(ErrMessage) ->
|
||||
jiffy:encode(#{
|
||||
iolist_to_binary(json:encode(#{
|
||||
<<"error">> => #{
|
||||
<<"code">> => ErrCode,
|
||||
<<"message">> => ErrMessage
|
||||
}
|
||||
}, [force_utf8]).
|
||||
})).
|
||||
|
||||
-spec uuid() -> string().
|
||||
uuid() ->
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user