-, Webgear , . , . - .
-, :
[{"/some/path", webgear_wrapper, {actual_resource, ["Some", extra, "Args"]}}].
, :
-record(context, {module, context, exports}).
init({Mod, Args}) ->
{ok, Context} = Mod:init(Args),
{ok,
exports(Mod) ->
dict:from_list(Mod:module_info(exports)).
Webgear, .
- ( , , ), , , :
call(
Func, Req, Default) ->
case dict:is_key(Func, Exports) of
true -> Mod:Func(Req, Cxt);
false -> {Default, Req, Cxt}
end.
call/4, , :
malformed_request(Req, Cxt) ->
% false here is the default value to return if the callback is missing
{Res, NewReq, NewCxt} = call(Cxt, malformed_request, Req, false),
% Now we must update the state accordingly
{Res, NewReq, Cxt#context{context = NewCxt}}.
, ( ). , , ( , ).