| 1 |
= cowboy:get_env(3) |
| 2 |
|
| 3 |
== Name |
| 4 |
|
| 5 |
cowboy:get_env - Retrieve a listener's environment value |
| 6 |
|
| 7 |
== Description |
| 8 |
|
| 9 |
[source,erlang] |
| 10 |
---- |
| 11 |
get_env(Name :: ranch:ref(), |
| 12 |
Key :: atom()) |
| 13 |
-> any() |
| 14 |
|
| 15 |
get_env(Name :: ranch:ref(), |
| 16 |
Key :: atom(), |
| 17 |
Default :: any()) |
| 18 |
-> any() |
| 19 |
---- |
| 20 |
|
| 21 |
Retrieve an environment value for a previously started |
| 22 |
listener. |
| 23 |
|
| 24 |
This function may crash when the key is missing from the |
| 25 |
environment and a default value is not provided. |
| 26 |
|
| 27 |
== Arguments |
| 28 |
|
| 29 |
Name:: |
| 30 |
|
| 31 |
The name of the listener to access. |
| 32 |
+ |
| 33 |
The name of the listener is the first argument given to the |
| 34 |
link:man:cowboy:start_clear(3)[cowboy:start_clear(3)], |
| 35 |
link:man:cowboy:start_tls(3)[cowboy:start_tls(3)] or |
| 36 |
link:man:ranch:start_listener(3)[ranch:start_listener(3)] function. |
| 37 |
|
| 38 |
Key:: |
| 39 |
|
| 40 |
The key in the environment map. Common keys include `dispatch` |
| 41 |
and `middlewares`. |
| 42 |
|
| 43 |
Default:: |
| 44 |
|
| 45 |
The default value if the key is missing. |
| 46 |
|
| 47 |
== Return value |
| 48 |
|
| 49 |
The environment value is returned on success. |
| 50 |
|
| 51 |
If a default was provided and the key is missing, then the |
| 52 |
default value is returned. |
| 53 |
|
| 54 |
An `exit:badarg` exception is thrown when the listener does |
| 55 |
not exist. |
| 56 |
|
| 57 |
An `exit:{badkey, Key}` exception is thrown when the key |
| 58 |
requested is missing and no default was provided. |
| 59 |
|
| 60 |
== Changelog |
| 61 |
|
| 62 |
* *2.11*: Function introduced. |
| 63 |
|
| 64 |
== Examples |
| 65 |
|
| 66 |
.Retrieve a listener's routes |
| 67 |
[source,erlang] |
| 68 |
---- |
| 69 |
Dispatch = cowboy:get_env(example, dispatch). |
| 70 |
---- |
| 71 |
|
| 72 |
== See also |
| 73 |
|
| 74 |
link:man:cowboy(3)[cowboy(3)], |
| 75 |
link:man:cowboy:start_clear(3)[cowboy:start_clear(3)], |
| 76 |
link:man:cowboy:start_tls(3)[cowboy:start_tls(3)], |
| 77 |
link:man:cowboy:set_env(3)[cowboy:set_env(3)], |
| 78 |
link:man:ranch:get_protocol_options(3)[ranch:get_protocol_options(3)] |