接口优化

This commit is contained in:
2026-08-13 09:16:54 +08:00
parent b964dcdcd9
commit 9e598a0318
12 changed files with 182 additions and 229 deletions
+4 -4
View File
@@ -7,12 +7,12 @@
namespace {
std::uint16_t parse_port(int argc, char** argv) {
constexpr std::uint16_t default_port = 8848;
if(argc != 3 || std::string_view(argv[1]) != "--port")
if (argc != 3 || std::string_view(argv[1]) != "--port")
return default_port;
unsigned value{};
const std::string_view text(argv[2]);
const auto [end, error] = std::from_chars(text.data(), text.data() + text.size(), value);
if(error != std::errc{} || end != text.data() + text.size() || value == 0 || value > 65535) {
if (error != std::errc{} || end != text.data() + text.size() || value == 0 || value > 65535) {
std::cerr << "Invalid port: " << text << '\n';
return 0;
}
@@ -21,9 +21,9 @@ std::uint16_t parse_port(int argc, char** argv) {
}
int main(int argc, char** argv) {
const std::uint16_t port = parse_port(argc, argv);
if(port == 0)
if (port == 0)
return 2;
std::cout << "http://127.0.0.1:8848" << std::endl;
const std::filesystem::path executable = std::filesystem::absolute(argv[0]);
return renderive::web::run_web_server(port, executable.parent_path());
return renderive::web::run_web_server(port, executable.parent_path().parent_path().parent_path());
}