summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMariano Guerra <[email protected]>2014-08-29 15:24:49 +0200
committerMariano Guerra <[email protected]>2014-08-29 15:24:49 +0200
commit04a6efe11c1114056ae1317cb71a495ba4adf231 (patch)
tree973dc0082b6aca7665705ec3a082a308bdbe259f
parent999f02f57c75edf7ddb5ed08b667ac6657418422 (diff)
downloadbullet-04a6efe11c1114056ae1317cb71a495ba4adf231.tar.gz
bullet-04a6efe11c1114056ae1317cb71a495ba4adf231.tar.bz2
bullet-04a6efe11c1114056ae1317cb71a495ba4adf231.zip
explain how to pass options to your own handler.
it wasn't clear where the user's handler options should go, after looking at the code and trying this is what I've found, correct me if there's a better way.
-rw-r--r--README.md17
1 files changed, 17 insertions, 0 deletions
diff --git a/README.md b/README.md
index e8ab736..e42aa15 100644
--- a/README.md
+++ b/README.md
@@ -35,6 +35,23 @@ The dispatch options for a Bullet handler looks as follow:
Simply define this in your dispatch list and your handler will be
available and handled by Bullet properly.
+The third element in the tuple ([{handler, my_stream}]) will be passed
+to init/4 as Opts, you can add your own options and get them using
+lists:keyfind, for example if we define our handler as:
+
+``` erlang
+{[<<"path">>, <<"to">>, <<"bullet">>], bullet_handler,
+ [{handler, my_stream}, {channel, "my channel"}]}
+```
+
+you can retrieve the channel value as follows:
+
+``` erlang
+init(_Transport, Req, Opts, _Active) ->
+ {channel, Channel} = lists:keyfind(channel, 1, Opts),
+ {ok, Req, #state{channel=Channel}}.
+```
+
Cowboy handler
--------------