mirror of
https://github.com/Karaka-Management/Developer-Guide.git
synced 2026-01-11 04:18:43 +00:00
update
This commit is contained in:
parent
a97c60fce2
commit
37295ee9f1
|
|
@ -1,6 +1,6 @@
|
||||||
```c++
|
```c++
|
||||||
/**
|
/**
|
||||||
* Karaka
|
* Jingga
|
||||||
*
|
*
|
||||||
* @package App
|
* @package App
|
||||||
* @copyright Dennis Eichhorn
|
* @copyright Dennis Eichhorn
|
||||||
|
|
@ -34,42 +34,42 @@ int main(int argc, char **argv)
|
||||||
/* --------------- Basic setup --------------- */
|
/* --------------- Basic setup --------------- */
|
||||||
|
|
||||||
const char *arg = Utils::ApplicationUtils::compile_arg_line(argc, argv);
|
const char *arg = Utils::ApplicationUtils::compile_arg_line(argc, argv);
|
||||||
|
|
||||||
// Set program path as cwd
|
// Set program path as cwd
|
||||||
char *cwd = Utils::ApplicationUtils::cwd();
|
char *cwd = Utils::ApplicationUtils::cwd();
|
||||||
if (cwd == NULL) {
|
if (cwd == NULL) {
|
||||||
printf("Couldn't get the CWD\n");
|
printf("Couldn't get the CWD\n");
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *cwdT = Utils::StringUtils::search_replace(cwd, "\\", "/");
|
char *cwdT = Utils::StringUtils::search_replace(cwd, "\\", "/");
|
||||||
free(cwd);
|
free(cwd);
|
||||||
cwd = cwdT;
|
cwd = cwdT;
|
||||||
|
|
||||||
Utils::ApplicationUtils::chdir_application(cwd, argv[0]);
|
Utils::ApplicationUtils::chdir_application(cwd, argv[0]);
|
||||||
|
|
||||||
// Check config
|
// Check config
|
||||||
if (!Utils::FileUtils::file_exists("config.json")) {
|
if (!Utils::FileUtils::file_exists("config.json")) {
|
||||||
Controller::ApiController::notInstalled(argc, argv);
|
Controller::ApiController::notInstalled(argc, argv);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------- App setup --------------- */
|
/* --------------- App setup --------------- */
|
||||||
|
|
||||||
// Load config
|
// Load config
|
||||||
FILE *in = fopen("config.json", "r");
|
FILE *in = fopen("config.json", "r");
|
||||||
if (in == NULL) {
|
if (in == NULL) {
|
||||||
printf("Couldn't open config.json\n");
|
printf("Couldn't open config.json\n");
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
app.config = nlohmann::json::parse(in);
|
app.config = nlohmann::json::parse(in);
|
||||||
|
|
||||||
fclose(in);
|
fclose(in);
|
||||||
|
|
||||||
// Setup db connection
|
// Setup db connection
|
||||||
DataStorage::Database::DbConnectionConfig dbdata = {
|
DataStorage::Database::DbConnectionConfig dbdata = {
|
||||||
DataStorage::Database::database_type_from_str(app.config["db"]["core"]["masters"]["admin"]["db"].get_ref<const std::string&>().c_str()),
|
DataStorage::Database::database_type_from_str(app.config["db"]["core"]["masters"]["admin"]["db"].get_ref<const std::string&>().c_str()),
|
||||||
|
|
@ -79,50 +79,50 @@ int main(int argc, char **argv)
|
||||||
app.config["db"]["core"]["masters"]["admin"]["login"].get_ref<const std::string&>().c_str(),
|
app.config["db"]["core"]["masters"]["admin"]["login"].get_ref<const std::string&>().c_str(),
|
||||||
app.config["db"]["core"]["masters"]["admin"]["password"].get_ref<const std::string&>().c_str(),
|
app.config["db"]["core"]["masters"]["admin"]["password"].get_ref<const std::string&>().c_str(),
|
||||||
};
|
};
|
||||||
|
|
||||||
app.pool = Threads::pool_create(app.config["app"]["threads"]["count"].get<int>());
|
app.pool = Threads::pool_create(app.config["app"]["threads"]["count"].get<int>());
|
||||||
|
|
||||||
app.db = DataStorage::Database::create_connection(dbdata);
|
app.db = DataStorage::Database::create_connection(dbdata);
|
||||||
app.db->connect();
|
app.db->connect();
|
||||||
|
|
||||||
/* --------------- Handle request --------------- */
|
/* --------------- Handle request --------------- */
|
||||||
|
|
||||||
// Handle routes
|
// Handle routes
|
||||||
Router::Router router = generate_routes(&app);
|
Router::Router router = generate_routes(&app);
|
||||||
Router::RouterFunc ptr = Router::match_route(&router, arg);
|
Router::RouterFunc ptr = Router::match_route(&router, arg);
|
||||||
|
|
||||||
// No endpoint found
|
// No endpoint found
|
||||||
if (ptr == NULL) {
|
if (ptr == NULL) {
|
||||||
ptr = &Controller::ApiController::printHelp;
|
ptr = &Controller::ApiController::printHelp;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dispatch found endpoint
|
// Dispatch found endpoint
|
||||||
(*ptr)(argc, argv);
|
(*ptr)(argc, argv);
|
||||||
|
|
||||||
/* --------------- Cleanup --------------- */
|
/* --------------- Cleanup --------------- */
|
||||||
|
|
||||||
Threads::pool_destroy(app.pool);
|
Threads::pool_destroy(app.pool);
|
||||||
|
|
||||||
DataStorage::Database::free_MapperData((DataStorage::Database::MapperData *) &Models::ResourceMapper);
|
DataStorage::Database::free_MapperData((DataStorage::Database::MapperData *) &Models::ResourceMapper);
|
||||||
|
|
||||||
app.db->close();
|
app.db->close();
|
||||||
app.db = NULL;
|
app.db = NULL;
|
||||||
|
|
||||||
Router::free_router(&router);
|
Router::free_router(&router);
|
||||||
|
|
||||||
free((char *) arg);
|
free((char *) arg);
|
||||||
arg = NULL;
|
arg = NULL;
|
||||||
|
|
||||||
// Reset CWD (don't know if this is necessary)
|
// Reset CWD (don't know if this is necessary)
|
||||||
chdir(cwd);
|
chdir(cwd);
|
||||||
|
|
||||||
free(cwd);
|
free(cwd);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
/**
|
/**
|
||||||
* Karaka
|
* Jingga
|
||||||
*
|
*
|
||||||
* @package Models
|
* @package Models
|
||||||
* @copyright Dennis Eichhorn
|
* @copyright Dennis Eichhorn
|
||||||
|
|
@ -146,12 +146,12 @@ Router::Router generate_routes(Application::ApplicationAbstract *app)
|
||||||
Controller::ApiController::app = app;
|
Controller::ApiController::app = app;
|
||||||
|
|
||||||
Router::Router router = Router::create_router(4);
|
Router::Router router = Router::create_router(4);
|
||||||
|
|
||||||
Router::set(&router, "^.*?\\-h *.*$", (void *) &Controller::ApiController::printHelp);
|
Router::set(&router, "^.*?\\-h *.*$", (void *) &Controller::ApiController::printHelp);
|
||||||
Router::set(&router, "^.*?\\-v *.*$", (void *) &Controller::ApiController::printVersion);
|
Router::set(&router, "^.*?\\-v *.*$", (void *) &Controller::ApiController::printVersion);
|
||||||
Router::set(&router, "^.*?\\-r *.*$", (void *) &Controller::ApiController::checkResources);
|
Router::set(&router, "^.*?\\-r *.*$", (void *) &Controller::ApiController::checkResources);
|
||||||
Router::set(&router, "^.*?\\-\\-install *.*$", (void *) &Controller::InstallController::installApplication);
|
Router::set(&router, "^.*?\\-\\-install *.*$", (void *) &Controller::InstallController::installApplication);
|
||||||
|
|
||||||
return router;
|
return router;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ The content of the language files is very simple. All you need is the module nam
|
||||||
```php
|
```php
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Karaka
|
* Jingga
|
||||||
*
|
*
|
||||||
* PHP Version 8.1
|
* PHP Version 8.1
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user