This commit is contained in:
anlicheng 2025-10-31 14:24:15 +08:00
parent a500d75af2
commit 6ba6864577

View File

@ -193,12 +193,12 @@ validate_config(Config) when is_map(Config) ->
{image, binary},
{container_name, binary},
{command, {list, binary}},
{restart, binary},
{privileged, boolean}
{restart, binary}
],
%%
Optional = [
{privileged, boolean},
{envs, {list, binary}},
{ports, {list, binary}},
{expose, {list, binary}},
@ -244,13 +244,13 @@ check_required(Config, Fields) ->
fun({Key, Type}, ErrAcc) ->
case maps:get(Key, Config, undefined) of
undefined ->
[io_lib:format("缺少必选参数: ~p", [Key]) | ErrAcc];
[io_lib:format("miss requied parameter: ~p", [Key]) | ErrAcc];
Value ->
case check_type(Value, Type) of
true ->
ErrAcc;
false ->
[io_lib:format("参数 ~p 类型错误,应为 ~p", [Key, Type]) | ErrAcc]
[io_lib:format("required parameter: ~p, type must be: ~p", [Key, type_name(Type)]) | ErrAcc]
end
end
end,
@ -270,7 +270,7 @@ check_optional(Config, Fields) ->
true ->
ErrAcc;
false ->
[io_lib:format("可选参数 ~p 类型错误,应为 ~p", [Key, Type]) | ErrAcc]
[io_lib:format("optional parameter: ~p, type must be: ~p", [Key, type_name(Type)]) | ErrAcc]
end
end
end,
@ -279,6 +279,31 @@ check_optional(Config, Fields) ->
%%------------------------------------------------------------------------------
%% binary版
%%------------------------------------------------------------------------------
-spec type_name(tuple() | atom()) -> binary().
type_name(binary) ->
<<"string">>;
type_name(integer) ->
<<"integer">>;
type_name(number) ->
<<"number">>;
type_name(list) ->
<<"list">>;
type_name({list, binary}) ->
<<"list of string">>;
type_name({list, number}) ->
<<"list of number">>;
type_name({list, integer}) ->
<<"list of integer">>;
type_name(map) ->
<<"map">>;
type_name({map, {binary, binary}}) ->
<<"map of string:string">>;
type_name({map, {binary, any}}) ->
<<"map of string:any">>;
type_name(boolean) ->
<<"boolean">>.
-spec check_type(Value :: any(), any()) -> boolean().
check_type(Value, binary) ->
is_binary(Value);
check_type(Value, integer) ->