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:
parent
91ae70b06c
commit
9255cdf1d7
6 changed files with 25 additions and 33 deletions
|
@ -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) ->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue