|
25 | 25 | protocol_error/3, protocol_error/4, protocol_error/1]).
|
26 | 26 | -export([not_found/1, assert_args_equivalence/4]).
|
27 | 27 | -export([dirty_read/1]).
|
28 |
| --export([table_lookup/2]). |
| 28 | +-export([table_lookup/2, set_table_value/4]). |
29 | 29 | -export([r/3, r/2, r_arg/4, rs/1]).
|
30 | 30 | -export([enable_cover/0, report_cover/0]).
|
31 | 31 | -export([enable_cover/1, report_cover/1]).
|
|
56 | 56 | -export([const_ok/0, const/1]).
|
57 | 57 | -export([ntoa/1, ntoab/1]).
|
58 | 58 | -export([is_process_alive/1]).
|
| 59 | +-export([pget/2, pget/3, pget_or_die/2]). |
59 | 60 |
|
60 | 61 | %%----------------------------------------------------------------------------
|
61 | 62 |
|
|
104 | 105 | -spec(table_lookup/2 ::
|
105 | 106 | (rabbit_framing:amqp_table(), binary())
|
106 | 107 | -> 'undefined' | {rabbit_framing:amqp_field_type(), any()}).
|
| 108 | +-spec(set_table_value/4 :: |
| 109 | + (rabbit_framing:amqp_table(), binary(), |
| 110 | + rabbit_framing:amqp_field_type(), rabbit_framing:amqp_value()) |
| 111 | + -> rabbit_framing:amqp_table()). |
| 112 | + |
107 | 113 | -spec(r/2 :: (rabbit_types:vhost(), K)
|
108 | 114 | -> rabbit_types:r3(rabbit_types:vhost(), K, '_')
|
109 | 115 | when is_subtype(K, atom())).
|
|
196 | 202 | -spec(ntoa/1 :: (inet:ip_address()) -> string()).
|
197 | 203 | -spec(ntoab/1 :: (inet:ip_address()) -> string()).
|
198 | 204 | -spec(is_process_alive/1 :: (pid()) -> boolean()).
|
| 205 | +-spec(pget/2 :: (term(), [term()]) -> term()). |
| 206 | +-spec(pget/3 :: (term(), [term()], term()) -> term()). |
| 207 | +-spec(pget_or_die/2 :: (term(), [term()]) -> term() | no_return()). |
199 | 208 |
|
200 | 209 | -endif.
|
201 | 210 |
|
@@ -268,6 +277,10 @@ table_lookup(Table, Key) ->
|
268 | 277 | false -> undefined
|
269 | 278 | end.
|
270 | 279 |
|
| 280 | +set_table_value(Table, Key, Type, Value) -> |
| 281 | + sort_field_table( |
| 282 | + lists:keystore(Key, 1, Table, {Key, Type, Value})). |
| 283 | + |
271 | 284 | r(#resource{virtual_host = VHostPath}, Kind, Name)
|
272 | 285 | when is_binary(Name) ->
|
273 | 286 | #resource{virtual_host = VHostPath, kind = Kind, name = Name};
|
@@ -897,3 +910,12 @@ is_process_alive(Pid) ->
|
897 | 910 | true -> true;
|
898 | 911 | _ -> false
|
899 | 912 | end.
|
| 913 | + |
| 914 | +pget(K, P) -> proplists:get_value(K, P). |
| 915 | +pget(K, P, D) -> proplists:get_value(K, P, D). |
| 916 | + |
| 917 | +pget_or_die(K, P) -> |
| 918 | + case proplists:get_value(K, P) of |
| 919 | + undefined -> exit({error, key_missing, K}); |
| 920 | + V -> V |
| 921 | + end. |
0 commit comments