0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-16 05:00:24 +00:00

Change the type of bindings from a list to a map

Maps make more sense because the keys are unique.
This commit is contained in:
Loïc Hoguin 2017-02-19 16:51:16 +01:00
parent 91ae70b06c
commit 9255cdf1d7
No known key found for this signature in database
GPG key ID: 71366FF21851DF03
6 changed files with 25 additions and 33 deletions

View file

@ -326,18 +326,18 @@ binding(Name, Req) ->
-spec binding(atom(), req(), Default) -> any() | Default when Default::any().
binding(Name, #{bindings := Bindings}, Default) when is_atom(Name) ->
case lists:keyfind(Name, 1, Bindings) of
{_, Value} -> Value;
false -> Default
case Bindings of
#{Name := Value} -> Value;
_ -> Default
end;
binding(Name, _, Default) when is_atom(Name) ->
Default.
-spec bindings(req()) -> [{atom(), any()}].
-spec bindings(req()) -> cowboy_router:bindings().
bindings(#{bindings := Bindings}) ->
Bindings;
bindings(_) ->
[].
#{}.
-spec header(binary(), req()) -> binary() | undefined.
header(Name, Req) ->