初始化及基本流程
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
int goahdStart(void) { char *argp, *auth, *home, *documents, *endpoints, *endpoint, *route, *tok, *lspec; int argind, duration; route = "route.txt"; auth = "auth.txt"; duration = 0; logSetPath("stdout:2"); // 打印 documents = ME_GOAHEAD_DOCUMENTS; //initPlatform(); if (websOpen(documents, route) < 0) { error("初始化WEB系统失败. Exiting."); return -1; } logHeader(); if (websLoad(auth) < 0) { error("Cannot load %s", auth); return -1; } if (websListen("http://*:80") < 0) { return -1; } websDefineHandler("test", testHandler, nullptr, nullptr, 0); websAddRoute("/test", "test", 0); websDefineAction("exampleAction", (void*)exampleAction); if (websGetBackground()) { if (daemon(0, 0) < 0) { error("Cannot run as daemon"); return -1; } } websServiceEvents(&finished); return 0; } |
goActions goActions定义
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
static void exampleAction(Webs *wp) { const char *io_val; io_val = websGetVar(wp, "val_led", nullptr); // 获取POST过来的数据 qDebug() << "on_led_set: " << io_val; websSetStatus(wp, 200); websWriteHeaders(wp, -1, nullptr); websWriteEndHeaders(wp); websWrite(wp, "%s", "<h4>hello GoAction!</h4>"); // 返回数据 websDone(wp); return nullptr; /****这句注册一个可以通过action/exampleGetAction访问的GoAction函数****/ websDefineAction("exampleAction", exampleGetAction); |