2021-02-28 01:05:03 +08:00
|
|
|
/*
|
|
|
|
* Copyright(C) 2021 hikyuu.org
|
|
|
|
*
|
|
|
|
* Create on: 2021-02-26
|
|
|
|
* Author: fasiondog
|
|
|
|
*/
|
|
|
|
|
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-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-04-24 23:07:57 +08:00
|
|
|
DB::init(fmt::format("{}/.hikyuu/trade.ini", getUserHome()));
|
2021-03-12 01:39:24 +08:00
|
|
|
|
|
|
|
LOG_INFO("start server ... You can press Ctrl-C stop");
|
2021-03-04 01:17:21 +08:00
|
|
|
|
2021-03-28 00:53:51 +08:00
|
|
|
HttpServer server("http://*", 9001);
|
2021-03-07 01:17:40 +08:00
|
|
|
|
2021-04-09 01:09:30 +08:00
|
|
|
try {
|
2021-04-24 17:54:53 +08:00
|
|
|
UserService login(HKU_SERVICE_API(user));
|
2021-04-09 01:09:30 +08:00
|
|
|
login.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);
|
|
|
|
|
|
|
|
server.start();
|
|
|
|
|
|
|
|
} catch (std::exception& e) {
|
|
|
|
LOG_FATAL(e.what());
|
|
|
|
server.stop();
|
|
|
|
} catch (...) {
|
|
|
|
LOG_FATAL("Unknow error!");
|
|
|
|
server.stop();
|
|
|
|
}
|
2021-03-30 01:01:38 +08:00
|
|
|
|
2021-02-28 01:05:03 +08:00
|
|
|
return 0;
|
|
|
|
}
|