erlang:基于cowboy,一键创建erlang…
来源:互联网 发布:java 模拟post请求 编辑:程序博客网 时间:2024/05/17 06:49
1、shell script如下:
#!/bin/bash
projectName=releaseErlangProject
rebarfile=rebar.config
projectPath=`pwd`/${projectName}
runScript=run.sh
#获取rebar工具
get_rebar(){
git clone git://github.com/rebar/rebar.git
cd rebar
./bootstrap
sudo mv rebar /usr/local/bin
}
#创建src目录
mk_app(){
goProjectPath
#rebar create-app appid=releaseErlangProject
rebar create template=simpleapp appid=${projectName}
echo "---SUCCESS mk_app!"
}
change_erlang_app(){
goProjectPath
cd src
accessPath="Dispatch=cowboy_router:compile([{'_',[{\"/\",${projectName}_handler,[]}]}]),cowboy:start_http(my_http_listener,100,[{port,8080}],[{env,[{dispatch,Dispatch}]}]),"
}
bootFile(){
goProjectPath
cd src
bootFileName=${projectName}_boot
bootFile=${bootFileName}.erl
echo "-module($bootFileName)." >> $bootFile
echo "-export([start/0, stop/0])." >> $bootFile
echo " "
echo " "
echo "start() ->" >> $bootFile
echo "application:start(ranch)," >> $bootFile
echo "application:start(crypto)," >> $bootFile
echo "application:start(cowlib)," >> $bootFile
echo "application:start(cowboy)," >> $bootFile
echo "application:start(${projectName})." >> $bootFile
echo "stop() ->" >> $bootFile
echo "application:stop(${projectName})," >> $bootFile
echo "application:stop(cowboy)," >> $bootFile
echo "application:stop(cowlib)," >> $bootFile
echo "application:stop(crypto)," >> $bootFile
echo "application:stop(ranch)." >> $bootFile
echo "---SUCCESS mk bootFile!"
}
#创建include目录
includeDir(){
goProjectPath
if [ ! -d "include" ] ; then
mkdir include
fi
echo "---SUCCESS mk includeDir!"
}
#创建include目录
privDir(){
goProjectPath
if [ ! -d "priv" ] ; then
mkdir priv
fi
echo "---SUCCESS mk privDir!"
}
#创建测试目录
testDir(){
goProjectPath
if [ ! -d "test" ] ; then
mkdir test
echo "{erl_opts, [debug_info,{i, \"test\"},{src_dirs,[\"src\"]}]}." >> ${rebarfile}
echo "{eunit_opts, [verbose, {report, {eunit_surefire, [{dir,\".\"}]}}]}." >> ${rebarfile}
echo "{cover_enabled, true}." >> ${rebarfile}
#testfile
fi
echo "---SUCCESS mk testDir!"
}
testfile(){
goProjectPath
testfile="demo.erl"
echo "-ifdef(TEST).
-include(\"${testfile}\").
-endif." >> ${testfile}
}
# Erlang/OTP 行为模式的模板
genTemplate(){
goProjectPath
rebar create template=simplesrv srvid=test_gen_server
rebar create template=simplefsm fsmid=test_gen_fsm
echo "---SUCCESS mk genTemplate!"
}
#创建工程依赖
depsDir(){
goProjectPath
if [ ! -d "deps" ] ; then
cowboy="{cowboy, \".*\", {git,\"https://github.com/ninenines/cowboy.git\"}}"
jiffy="{jiffy, \".*\", {git,\"https://github.com/davisp/jiffy.git\"}}"
emysql="{emysql, \".*\", {git,\"https://github.com/Eonblast/Emysql.git\"}}"
split=","
objects=${cowboy}
#objects=${cowboy}${split} ${jiffy}${split}${emysql}
echo "{deps, [${objects}]}." >> ${rebarfile}
# get deps
rebar get-deps
fi
echo "---SUCCESS mk depsDir!"
}
goProjectPath(){
if [ ${projectPath} != `pwd`} ]; then
cd ${projectPath}
fi
}
mkHandler(){
goProjectPath
cd src
echo "-module(${projectName}_handler).
-author(\"wxm\").
%% API
-behaviour(cowboy_handler).
-export([init/2]).
-export([terminate/3]).
init(Req, _Opts) ->
terminate(_Reason, _Req, _State) ->
echo "---SUCCESS
}
未完待续...
0 0
- erlang:基于cowboy,一键创建erlang…
- erlang:基于cowboy,一键创建erlang…
- Erlang cowboy 入门参考
- Erlang cowboy websocket 服务器
- Erlang cowboy routing 路由
- Erlang cowboy 架构
- cowboy erlang 文件上传
- cowboy erlang 上传文件
- Erlang搭建cowboy服务器
- Erlang cowboy http request生命周期
- Erlang——cowboy源码剖析
- Erlang cowboy 处理简单的HTTP请求
- Erlang cowboy 处理不规范的客户端
- Erlang
- Erlang
- Erlang
- erlang
- Erlang
- android应用开发:音乐播放器(1)
- android应用开发:音乐播放器(2)…
- android应用开发 监听拨号键盘
- android应用:多部手机通过usbhub…
- ubuntu下编译erlang-mysql-driver
- erlang:基于cowboy,一键创建erlang…
- erlang:基于cowboy,一键创建erlang…
- 代码审查
- JDK源码中使用的设计模式
- 虚拟机下 linux minicom使用
- 黑马程序员——TreeSet集合储存自定义对象
- 雷观(十五):提高生产力和程序员价值的2种方法
- 冒泡排序
- Android -- 采用系统相册浏览指定路径下照片