goahead-4.0.2

论坛 期权论坛 脚本     
匿名技术用户   2020-12-27 10:21   11   0

源码下载

goahead源码

git clone http://github.com/embedthis/goahead

https://www.embedthis.com/goahead/

Makeme源码

git clone https://github.com/embedthis/makeme.git

https://www.embedthis.com/makeme/

交叉编译(使用Makeme)

Makeme安装

  • make boot
  • sudo make install

goahead交叉编译

  • CC=/xxxx/bin/mipsel-linux-gcc CFLAGS=-I/xxxx/include LDFLAGS=-L/xxxx/lib ./configure --platform linux-mips --without ssl
  • me

action模块测试

定义action方法

static void myactiontest(Webs *wp)
{
 char *name = websGetVar(wp, "name", "");
 char *age = websGetVar(wp, "age", "");
 char writedata[128];
 int length = 0;
 if(strlen(name)<1 || strlen(age)<1)
 {
  length = snprintf(writedata, sizeof(writedata), "name or age is NULL, please check !!!");
 }
 else
 {
  length = snprintf(writedata, sizeof(writedata), "name = %s, age = %s", name, age);
 }
 websSetStatus(wp, 200);
 websWriteHeaders(wp, length, 0);
 websWriteEndHeaders(wp);
 websWrite(wp, writedata);
 websDone(wp);
}

注册action方法

websDefineAction("actiontest", myactiontest);

测试action方法

<form action="action/actiontest" method="get">
 <input type="text" name="name" placeholder="姓名"/>
 <input type="text" name="age" placeholder="年龄"/>
 <input type="submit" name="" id="" value="goActions" />
</form>

JST模块测试

定义JST方法

extern int outputmytable(int ejid, Webs *wp, int argc, char **argv)
{
 websWrite(wp, "<tr>");
 websWrite(wp, "<td>CH340</td>");
 websWrite(wp, "<td>115200</td>");
 websWrite(wp, "<td>8</td>");
 websWrite(wp, "<td>1</td>");
 websWrite(wp, "<td>0</td>");
 websWrite(wp, "</tr>");
}

注册JST方法

websDefineJst("outputmytable", outputmytable);

测试JST方法

<table border="1" cellpadding="5" cellspacing="0" id="mytable">
  <caption style="font-weight: bold;">串口状态</caption>
  <tr>
   <th width="20%">线路协议</th>
   <th width="20%">波特率</th>
   <th width="20%">数据位</th>
   <th width="20%">起始位</th>
   <th width="20%">停止位</th>
  </tr>
  <%outputmytable();%>
</table>

配置文件:route.txt

route uri=/cgi-bin dir=cgi-bin handler=cgi             //cgi方法请求的路径
route uri=/action handler=action                       //action方法                        
route uri=/ extensions=jst,asp,html handler=jst        //可以使用jst方法页面的声明
route uri=/ methods=OPTIONS|TRACE handler=options

#   For legacy GoAhead applications using /goform
route uri=/goform handler=action

运行

编译完成后在 build/linux-mips-debug/bin 目录产生可执行文件和链接库,将 src 目录下的 auth.txt 、route.txt 和 web 拷贝到该目录,交叉编译情况下将这些文件拷贝到板子上即可

sudo ./goahead -v --home PATH1 PATH2

-v     : 打开运行日志
--home : 指定运行目录, 第一个参数 PATH1 是配置文件的所在目录 第二个参数 PATH2 是web页面所在目录

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP