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

Add cowboy:get_env/2,3

This commit is contained in:
Loïc Hoguin 2024-01-05 12:31:48 +01:00
parent 8f49f8792a
commit 67df6fedae
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764
5 changed files with 119 additions and 5 deletions

View file

@ -17,6 +17,8 @@
-export([start_clear/3]).
-export([start_tls/3]).
-export([stop_listener/1]).
-export([get_env/2]).
-export([get_env/3]).
-export([set_env/3]).
%% Internal.
@ -69,6 +71,18 @@ ensure_connection_type(TransOpts) ->
stop_listener(Ref) ->
ranch:stop_listener(Ref).
-spec get_env(ranch:ref(), atom()) -> ok.
get_env(Ref, Name) ->
Opts = ranch:get_protocol_options(Ref),
Env = maps:get(env, Opts, #{}),
maps:get(Name, Env).
-spec get_env(ranch:ref(), atom(), any()) -> ok.
get_env(Ref, Name, Default) ->
Opts = ranch:get_protocol_options(Ref),
Env = maps:get(env, Opts, #{}),
maps:get(Name, Env, Default).
-spec set_env(ranch:ref(), atom(), any()) -> ok.
set_env(Ref, Name, Value) ->
Opts = ranch:get_protocol_options(Ref),