fix
This commit is contained in:
parent
a500d75af2
commit
6ba6864577
@ -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) ->
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user