forked from ninenines/cowboy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugins.mk
75 lines (57 loc) · 1.35 KB
/
plugins.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# See LICENSE for licensing information.
# Plain HTTP handlers.
define tpl_cowboy.http
-module($(n)).
-behavior(cowboy_handler).
-export([init/2]).
init(Req, State) ->
{ok, Req, State}.
endef
# Loop handlers.
define tpl_cowboy.loop
-module($(n)).
-behavior(cowboy_loop).
-export([init/2]).
-export([info/3]).
init(Req, State) ->
{cowboy_loop, Req, State, hibernate}.
info(_Info, Req, State) ->
{ok, Req, State, hibernate}.
endef
# REST handlers.
define tpl_cowboy.rest
-module($(n)).
-behavior(cowboy_rest).
-export([init/2]).
-export([content_types_provided/2]).
-export([to_html/2]).
init(Req, State) ->
{cowboy_rest, Req, State}.
content_types_provided(Req, State) ->
{[
{{<<"text">>, <<"html">>, '*'}, to_html}
], Req, State}.
to_html(Req, State) ->
{<<"<html><body>This is REST!</body></html>">>, Req, State}.
endef
# Websocket handlers.
define tpl_cowboy.ws
-module($(n)).
-behavior(cowboy_websocket).
-export([init/2]).
-export([websocket_init/1]).
-export([websocket_handle/2]).
-export([websocket_info/2]).
init(Req, State) ->
{cowboy_websocket, Req, State}.
websocket_init(State) ->
{ok, State}.
websocket_handle({text, Data}, State) ->
{reply, {text, Data}, State};
websocket_handle({binary, Data}, State) ->
{reply, {binary, Data}, State};
websocket_handle(_Frame, State) ->
{ok, State}.
websocket_info(_Info, State) ->
{ok, State}.
endef