cowboy的路由方式
直接贴代码
route_helper.erl
-module(route_helper). -export([get_routes/]). get_routes() ->
[
{'_', [
%% 路由的一些情况
{ "/catch_all_handler/[...]", catch_all_handler, [] },
{ "/:aa/:bb/[:c]", test_handler, [aaa] }
]}
].
catch_all_handler里面处理以catch_all_handler开始的所有url请求
catch_all_handler.erl
-module(catch_all_handler). -export([init/3]).
-export([handle/2]).
-export([terminate/3]). init(_Transport, Req, []) ->
{ok, Req, undefined}. handle(Req, State) ->
{Path,_} = cowboy_req:path(Req),
{PathList, _} = cowboy_req:path_info(Req), lists:foreach(
fun(PathArg)->
io:format("catch_all_handler path is ~p, args ~p~n",[Path,PathArg])
end,
PathList
),
{ok, Req, State}. terminate(_Reason, _Req, _State) ->
ok.
test_handler.erl
-module(test_handler). -export([init/3]).
-export([handle/2]).
-export([terminate/3]). init(_Transport, Req, [Options]) ->
io:format("options ~p~n",[Options]),
{ok, Req, undefined}. handle(Req, State) ->
{PathInfo,_} = cowboy_req:path(Req),
{Arg1,_} = cowboy_req:binding(aa,Req),
{Arg2,_} = cowboy_req:binding(bb,Req),
io:format("test_handler path is ~p, arg1 ~p,arg2 ~p~n",[PathInfo,Arg1,Arg2]),
{ok, Req, State}. terminate(_Reason, _Req, _State) ->
ok.
init里面的Option就是aaa,cowboy_req:bing()来获取后面的url,[:c]为可选url,可以写,可以不写
cowboy的路由方式的更多相关文章
- Erlang cowboy routing 路由
Erlang cowboy routing 路由 本文译自: http://ninenines.eu/docs/en/cowboy/1.0/guide/routing/ Routing 默认情况下,C ...
- Docker容器跨主机通信之:直接路由方式
一.Docker网络基本原理 直观上看,要实现网络通信,机器需要至少一个网络接口(物理接口或虚拟接口)与外界相通,并可以收发数据包:此外,如果不同子网之间要进行通信,需要额外的路由机制. Docker ...
- node——四种注册路由方式
app.get和app.post 1.请求的方法必须是get/post2.请求的路径的pathname必须等于(====)路径 app.use 1.在进行路由匹配的时候不限定方法,什么请求方法都可 ...
- Windows 系统cmd设置添加静态路由方式
电脑上添加静态路由,cmd设置路由 方法/步骤 1.首先在“运行”窗口输入cmd(按WIN+R打开运行窗口),然后回车进入命令行,输入 route add 10.253.251.0 mask ...
- asp.net 二级域名(路由方式实现)
自从微软发布 ASP.NET MVC 和routing engine (System.Web.Routing)以来,就设法让我们明白你完全能控制URL和routing,只要与你的application ...
- Windows 系统PowerShell或cmd设置添加静态路由方式
电脑上添加静态路由,PowerShell或cmd设置路由 方法/步骤1.首先以管理员身份在“运行”窗口输入cmd或PowerShell(按WIN+R打开运行窗口),然后回车进入命令行,输入 route ...
- renren-fast-vue-动态路由-添加路由-方式一(直接在原有结构上添加)
在原有文件夹夹下新建自己的组件 在 mock/modules/sys-menu.js 中引入 实现路由的添加
- H3C 不适当的VLAN间路由方式
- express for node 路由route几种实现方式的思考
1.路由实现方式和顺序 express框架创建的模板app,js中默认代码 var express = require('express'); var routes = require('./rout ...
随机推荐
- Ansible 小手册系列 二十(经常遇到的问题)
(1). 怎么为任务设置环境变量? - name: set environment shell: echo $PATH $SOME >> /tmp/a.txt environment: P ...
- HTML5:了解Polyfills
利用 HTML5 来搭建网站和应用可能是一项艰巨的任务.尽管现在越来越多的现代浏览器正在更多的支持Html5新特性,但实际上只有很少部分人能够幸运的只需要为这些最新的浏览器编写代码.作为一个专业的开发 ...
- 004——数组(四)array_search() array_change_key_case() array_chunk() array_combine() array_diff() array_diff_key() array_diff_assoc
<?php /** * in_array() 判断一个内容是否在数组中: */ /*$arr=array(1,2,3,4,5); if (in_array('1',$arr,TRUE)){ // ...
- 网页重构中区分IE6、IE7、IE8及标准浏览器的最佳方法
由于万恶的IE6和IE7,我们在页面重构时不免要对其进行各种bug修复及差异化处理.在标准浏览器中可实现的效果在IE里却有各种离奇问题,例如IE6.IE7不能良好应对的inline-block和.cl ...
- Python 读取window下UTF-8-BOM 文件
with open('target.txt', 'r', encoding='utf_8_sig') as fp: print(fp.read())
- 【LeetCode 111_二叉树_遍历】Minimum Depth of Binary Tree
解法一:递归 int minDepth(TreeNode* root) { if (root == NULL) ; if (root->left == NULL) { ; } else if ( ...
- flash cc新建swc文件
- flowable 五个引擎和组成引擎的服务
一.flowable的五个引擎 flowable包含五个引擎,分别是: 1.内容引擎 ContentEngine 2.身份识别引擎 IdmEngine 3.表单引擎 FormEngine 4.决策引擎 ...
- dyld: lazy symbol binding failed: Symbol not found: ___sincosf_stret
This is the error I get: dyld: lazy symbol binding failed: Symbol not found: ___sincosf_stret Refere ...
- Elasticsearch安装配置和测试
官方教程:https://www.elastic.co/guide/en/elasticsearch/reference/master/_installation.html 中文教程:https:// ...