fix undefined

This commit is contained in:
anlicheng 2026-05-09 23:03:13 +08:00
parent ba7c2b8ecd
commit 493d637565
3 changed files with 3 additions and 9 deletions

View File

@ -42,7 +42,7 @@
- command 顶层、`target`、deploy `params``create` 中间结构都使用 binary key。
- `<<"action">>` 的取值使用 binary`<<"list">>``<<"deploy">>``<<"start">>``<<"stop">>``<<"kill">>``<<"remove">>``<<"config">>`
- `<<"__undefined__">>` 只在 Docker 参数构造读取可选字段时按需当成 `undefined` 处理
- `undefined` 作为 Erlang 已有 atom 可以直接出现在 safe term 中;协议不再使用额外的哨兵 binary 表示缺省值
下面各小节描述的是 `efka` 直接接收和处理的 map 格式。

View File

@ -318,13 +318,7 @@ add_unique_front([Item | Rest], List) ->
-spec field(map(), binary(), term()) -> term().
field(Map, Key, Default) when is_map(Map), is_binary(Key) ->
safe_value(maps:get(Key, Map, Default)).
-spec safe_value(term()) -> term().
safe_value(<<"__undefined__">>) ->
undefined;
safe_value(Value) ->
Value.
maps:get(Key, Map, Default).
-spec to_binary(binary() | list() | atom() | any()) -> binary().
to_binary(Value) when is_binary(Value) ->

View File

@ -326,7 +326,7 @@ safe_term(true) ->
safe_term(false) ->
false;
safe_term(undefined) ->
<<"__undefined__">>;
undefined;
safe_term(Value) when is_atom(Value) ->
atom_to_binary(Value, utf8);
safe_term(Value) when is_map(Value) ->