2021-02-28 01:05:03 +08:00
|
|
|
/*
|
|
|
|
* Copyright(C) 2021 hikyuu.org
|
|
|
|
*
|
|
|
|
* Create on: 2021-02-26
|
|
|
|
* Author: fasiondog
|
|
|
|
*/
|
|
|
|
|
2021-05-02 02:10:27 +08:00
|
|
|
#include <locale>
|
2021-06-01 02:06:29 +08:00
|
|
|
#include <csignal>
|
2021-04-09 01:09:30 +08:00
|
|
|
#include <hikyuu/utilities/os.h>
|
2021-02-28 01:05:03 +08:00
|
|
|
#include "http/HttpServer.h"
|
2021-04-24 23:07:57 +08:00
|
|
|
#include "db/db.h"
|
2021-04-24 17:54:53 +08:00
|
|
|
#include "service/user/UserService.h"
|
2021-03-22 01:38:03 +08:00
|
|
|
#include "service/assist/AssistService.h"
|
2021-03-30 01:01:38 +08:00
|
|
|
#include "service/trade/TradeService.h"
|
2021-03-04 01:17:21 +08:00
|
|
|
|
2021-02-28 01:05:03 +08:00
|
|
|
using namespace hku;
|
|
|
|
|
2021-03-22 01:38:03 +08:00
|
|
|
#define HKU_SERVICE_API(name) "/hku/" #name "/v1"
|
|
|
|
|
2021-06-01 02:06:29 +08:00
|
|
|
void signal_handle(int signal) {
|
|
|
|
if (signal == SIGINT || signal == SIGTERM) {
|
2021-06-11 02:09:58 +08:00
|
|
|
APP_INFO("Shutdown now ...");
|
2021-06-01 02:06:29 +08:00
|
|
|
HttpServer::stop();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-28 01:05:03 +08:00
|
|
|
int main(int argc, char* argv[]) {
|
2021-03-12 01:39:24 +08:00
|
|
|
init_server_logger();
|
|
|
|
|
2021-05-03 01:46:08 +08:00
|
|
|
// 初始化多语言支持
|
|
|
|
MOHelper::init();
|
2021-05-02 02:10:27 +08:00
|
|
|
|
2021-06-01 02:06:29 +08:00
|
|
|
std::signal(SIGINT, signal_handle);
|
|
|
|
std::signal(SIGTERM, signal_handle);
|
|
|
|
|
2021-03-28 00:53:51 +08:00
|
|
|
HttpServer server("http://*", 9001);
|
2021-06-01 02:06:29 +08:00
|
|
|
HttpHandle::enableTrace(true, false);
|
2021-03-07 01:17:40 +08:00
|
|
|
|
2021-04-09 01:09:30 +08:00
|
|
|
try {
|
2021-06-01 02:06:29 +08:00
|
|
|
// 设置 404 返回信息
|
|
|
|
server.set_error_msg(
|
|
|
|
NNG_HTTP_STATUS_NOT_FOUND,
|
|
|
|
fmt::format(R"({{"result": false,"errcode":{}, "errmsg":"Not Found"}})",
|
|
|
|
NNG_HTTP_STATUS_NOT_FOUND));
|
|
|
|
|
2021-04-25 01:53:22 +08:00
|
|
|
DB::init(fmt::format("{}/.hikyuu/trade.ini", getUserHome()));
|
|
|
|
|
|
|
|
UserService usr_service(HKU_SERVICE_API(user));
|
|
|
|
usr_service.bind(&server);
|
2021-02-28 01:05:03 +08:00
|
|
|
|
2021-04-09 01:09:30 +08:00
|
|
|
AssistService assist(HKU_SERVICE_API(assist));
|
|
|
|
assist.bind(&server);
|
2021-03-22 01:38:03 +08:00
|
|
|
|
2021-04-24 23:07:57 +08:00
|
|
|
TradeService trade(HKU_SERVICE_API(trade));
|
2021-04-09 01:09:30 +08:00
|
|
|
trade.bind(&server);
|
|
|
|
|
2021-06-11 02:09:58 +08:00
|
|
|
APP_INFO("start server ... You can press Ctrl-C stop");
|
2021-04-09 01:09:30 +08:00
|
|
|
server.start();
|
|
|
|
|
|
|
|
} catch (std::exception& e) {
|
2021-06-11 02:09:58 +08:00
|
|
|
APP_FATAL(e.what());
|
2021-04-09 01:09:30 +08:00
|
|
|
server.stop();
|
|
|
|
} catch (...) {
|
2021-06-11 02:09:58 +08:00
|
|
|
APP_FATAL("Unknow error!");
|
2021-04-09 01:09:30 +08:00
|
|
|
server.stop();
|
|
|
|
}
|
2021-03-30 01:01:38 +08:00
|
|
|
|
2021-02-28 01:05:03 +08:00
|
|
|
return 0;
|
|
|
|
}
|