的init/2牛仔hello_handler不确定
问题描述:
我下面https://ninenines.eu/docs/en/cowboy/2.0/guide/getting_started/的init/2牛仔hello_handler不确定
当我运行
gmake new t=cowboy_http n=hello_handler
这将创建的src/hello_handler
-module(hello_handler).
-behaviour(cowboy_http_handler).
-export([init/3]).
-export([handle/2]).
-export([terminate/3]).
-record(state, {
}).
init(_, Req, _Opts) ->
{ok, Req, #state{}}.
handle(Req, State=#state{}) ->
{ok, Req2} = cowboy_req:reply(200, Req),
{ok, Req2, State}.
terminate(_Reason, _Req, _State) ->
ok.
指示说要修改的init/2但只有init/3。这份文件是否过时..?
答
您正在查看的文档与您正在查看的牛仔版本不匹配。该文档适用于2.x版,处理程序适用于1.x版。
Cowboy 1.x系列实现了一个具有行为的http处理程序。当您从模板生成处理程序时,该处理程序将实现该行为。
然而,在牛仔2.x中,处理程序只需要实现init/2
,并不需要再执行行为。
当你检查出牛仔,你可以用make docs
使文档吧。然后你可以在doc
本地浏览它们。这样,你就可以保证有与你的牛仔版本相匹配的文档。
+0
太棒了,我会用'make docs',谢谢! – quantumpotato
它看起来像'erlang.mk'有一个过时的。[链接](https://github.com/ninenines/cowboy/issues/994) – hyun
谢谢!这对我有用.. – quantumpotato