Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
53 lines (45 loc) · 1.56 KB
/
Copy pathmain.cpp
File metadata and controls
53 lines (45 loc) · 1.56 KB
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
48
49
50
51
52
53
#include "./config/config.h"
#include "webserver.h"
#include "./CGImysql/sql_connection_pool.h"
#include "./analytics/click_event_producer.h"
#include "./handler/health_handler.h"
#include "./handler/metrics_handler.h"
#include "./handler/short_url_handler.h"
#include "./observability/structured_logger.h"
#include "./shorturl/short_url_cache.h"
#include "./shorturl/shard_router.h"
#include "./shorturl/snowflake.h"
int main(int argc, char *argv[])
{
Config config;
std::string config_path = "config/config.yaml";
if (argc > 1)
config_path = argv[1];
if (!config.load(config_path))
fprintf(stderr, "Config load failed, using defaults\n");
if (config.snowflake_worker_id >= 0)
{
// Pin the id-worker bits across both generator instances (short codes
// and click event ids); default is pid-derived, which already keeps
// same-host instances apart.
SnowflakeIdGenerator::set_worker_id(config.snowflake_worker_id);
}
ShardRouter::instance().init(config);
StructuredLogger::instance().init(config);
ShortUrlCache::instance().init(config);
ClickEventProducer::instance().init(config);
init_short_url_handler(config);
register_health_routes();
register_metrics_routes();
register_short_url_routes();
WebServer server;
server.init(config);
server.log_write();
server.sql_pool();
ShortUrlCache::instance().warmup(connection_pool::GetInstance());
server.thread_pool();
server.trig_mode();
server.eventListen();
server.eventLoop();
return 0;
}