mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-15 12:40:25 +00:00
Convert the REST streaming example to a release
This commit is contained in:
parent
630a805541
commit
7a7e144a0d
8 changed files with 42 additions and 39 deletions
|
@ -1,15 +0,0 @@
|
|||
%% Feel free to use, reuse and abuse the code in this file.
|
||||
|
||||
-module(rest_stream_response).
|
||||
|
||||
%% API.
|
||||
-export([start/0]).
|
||||
|
||||
%% API.
|
||||
|
||||
start() ->
|
||||
ok = application:start(crypto),
|
||||
ok = application:start(cowlib),
|
||||
ok = application:start(ranch),
|
||||
ok = application:start(cowboy),
|
||||
ok = application:start(rest_stream_response).
|
|
@ -26,7 +26,8 @@ start(_Type, _Args) ->
|
|||
stop(_State) ->
|
||||
ok.
|
||||
|
||||
generate_rows(_Table, 0) -> ok;
|
||||
generate_rows(_Table, 0) ->
|
||||
ok;
|
||||
generate_rows(Table, N) ->
|
||||
ets:insert(Table, {key(), val(), val()}),
|
||||
generate_rows(Table, N - 1).
|
||||
|
|
|
@ -22,12 +22,11 @@ content_types_provided(Req, State) ->
|
|||
streaming_csv(Req, Table) ->
|
||||
{N, Req1} = cowboy_req:binding(v1, Req, 1),
|
||||
MS = [{{'$1', '$2', '$3'}, [{'==', '$2', N}], ['$$']}],
|
||||
|
||||
{{stream, result_streamer(Table, MS)}, Req1, Table}.
|
||||
|
||||
result_streamer(Table, MS) ->
|
||||
fun (Socket, Transport) ->
|
||||
send_records(Socket, Transport, ets:select(Table, MS, 1))
|
||||
send_records(Socket, Transport, ets:select(Table, MS, 1))
|
||||
end.
|
||||
|
||||
send_records(Socket, Transport, {[Rec], Cont}) ->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue