fix undefined
This commit is contained in:
parent
ba7c2b8ecd
commit
493d637565
@ -42,7 +42,7 @@
|
|||||||
|
|
||||||
- command 顶层、`target`、deploy `params`、`create` 中间结构都使用 binary key。
|
- command 顶层、`target`、deploy `params`、`create` 中间结构都使用 binary key。
|
||||||
- `<<"action">>` 的取值使用 binary:`<<"list">>`、`<<"deploy">>`、`<<"start">>`、`<<"stop">>`、`<<"kill">>`、`<<"remove">>`、`<<"config">>`。
|
- `<<"action">>` 的取值使用 binary:`<<"list">>`、`<<"deploy">>`、`<<"start">>`、`<<"stop">>`、`<<"kill">>`、`<<"remove">>`、`<<"config">>`。
|
||||||
- `<<"__undefined__">>` 只在 Docker 参数构造读取可选字段时按需当成 `undefined` 处理。
|
- `undefined` 作为 Erlang 已有 atom 可以直接出现在 safe term 中;协议不再使用额外的哨兵 binary 表示缺省值。
|
||||||
|
|
||||||
下面各小节描述的是 `efka` 直接接收和处理的 map 格式。
|
下面各小节描述的是 `efka` 直接接收和处理的 map 格式。
|
||||||
|
|
||||||
|
|||||||
@ -318,13 +318,7 @@ add_unique_front([Item | Rest], List) ->
|
|||||||
|
|
||||||
-spec field(map(), binary(), term()) -> term().
|
-spec field(map(), binary(), term()) -> term().
|
||||||
field(Map, Key, Default) when is_map(Map), is_binary(Key) ->
|
field(Map, Key, Default) when is_map(Map), is_binary(Key) ->
|
||||||
safe_value(maps:get(Key, Map, Default)).
|
maps:get(Key, Map, Default).
|
||||||
|
|
||||||
-spec safe_value(term()) -> term().
|
|
||||||
safe_value(<<"__undefined__">>) ->
|
|
||||||
undefined;
|
|
||||||
safe_value(Value) ->
|
|
||||||
Value.
|
|
||||||
|
|
||||||
-spec to_binary(binary() | list() | atom() | any()) -> binary().
|
-spec to_binary(binary() | list() | atom() | any()) -> binary().
|
||||||
to_binary(Value) when is_binary(Value) ->
|
to_binary(Value) when is_binary(Value) ->
|
||||||
|
|||||||
@ -326,7 +326,7 @@ safe_term(true) ->
|
|||||||
safe_term(false) ->
|
safe_term(false) ->
|
||||||
false;
|
false;
|
||||||
safe_term(undefined) ->
|
safe_term(undefined) ->
|
||||||
<<"__undefined__">>;
|
undefined;
|
||||||
safe_term(Value) when is_atom(Value) ->
|
safe_term(Value) when is_atom(Value) ->
|
||||||
atom_to_binary(Value, utf8);
|
atom_to_binary(Value, utf8);
|
||||||
safe_term(Value) when is_map(Value) ->
|
safe_term(Value) when is_map(Value) ->
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user