- SignalDesk1小时前
Original Summary
First of all, I'm not claiming that my framework will save industrial C/C++ development. It's just a hobby project.<p>Industrial code needs safer code, not easier code. But when you're developing a blog at 8 PM, long template errors are annoying.<p>You need CRUD and RDBMS. It's simple.<p>CWIST is for that kind of work.<p>It sacrifices memory safety, smart pointers, and modern C++ abstractions. In return, compile errors are more predictable.<p><pre><code> #include <stdio.h> #include <cwist/app.h> #include <cwist/core/db/pool.h> #include <cwist/core/template/template.h> static cwist_db_pool_t g_db_pool; static void send_error(cwist_http_response res, const char msg) { res->status_code = CWIST_HTTP_INTERNAL_ERROR; cwist_http_header_add(&res->headers, "Content-Type", "text/plain"); cwist_sstring_assign(res->body, msg); } static void render(cwist_http_response res, const char path, cJSON ctx) { cwist_sstring html = cwist_template_render_file(path, ctx); if (html) { cwist_http_header_add(&res->headers, "Content-Type", "text/html"); cwist_sstring_assign(res->body, html->data); cwist_sstring_destroy(html); } cJSON_Delete(ctx); } static void handle_index(cwist_http_request req, cwist_http_response res) { (void)req; cJSON ctx = cJSON_CreateObject(); cJSON_AddStringToObject(ctx, "title", "CWIST Example"); cJSON_AddStringToObject(ctx, "greeting", "Hello from CWIST"); render(res, "templates/index.html", ctx); } static void handle_users(cwist_http_request req, cwist_http_response res) { (void)req; if (!g_db_pool) return send_error(res, "database pool unavailable"); cwist_db_pool_exec(g_db_pool, "CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT);" "INSERT INTO users (name) SELECT 'Alice' WHERE NOT EXISTS " "(SELECT 1 FROM users WHERE name = 'Alice');" "INSERT INTO users (name) SELECT 'Bob' WHERE NOT EXISTS " "(SELECT 1 FROM users WHERE name = 'Bob');"); cJSON rows = NULL; if (cwist_db_pool_query(g_db_pool, "SELECT id, name FROM users ORDER BY id;", &rows).error.err_i16) return send_error(res, "failed to query database"); cJSON ctx = cJSON_CreateObject(); cJSON_AddItemToObject(ctx, "users", rows ? rows : cJSON_CreateArray()); render(res, "templates/users.html", ctx); } static void handle_health(cwist_http_request req, cwist_http_response res) { (void)req; cwist_http_header_add(&res->headers, "Content-Type", "text/plain"); cwist_sstring_assign(res->body, "ok"); } int main(void) { g_db_pool = cwist_db_pool_create("./app.db", 1); if (!g_db_pool) return 1; cwist_app *app = cwist_app_create(); cwist_app_get(app, "/", handle_index); cwist_app_get(app, "/users", handle_users); cwist_app_get(app, "/health", handle_health); cwist_app_use_https(app, "cert.pem", "key.pem"); cwist_app_listen(app, 8082); cwist_app_destroy(app); cwist_db_pool_destroy(g_db_pool); return 0; } </code></pre> Code style is old and still small. The code is simple and stupid.<p>CWIST functions use the same
cwist_xx_xxnaming format. It's consistent. It's harder to make a slop in CWIST.<p>Features<p>- CWIST GC for fast prototyping. It's closer to a garbage sweeper than a traditional GC, and lighter. - Dev blog engine - HTML Template Engine - WASM<p>External benchmark: <a href="https://web-frameworks-benchmark.netlify.app/compare?f=cwist,drogon" rel="nofollow">https://web-frameworks-benchmark.netlify.app/compare?f=cwist...</a><p>Latest results may be masked: <a href="https://github.com/the-benchmarker/web-frameworks/issues/9775" rel="nofollow">https://github.com/the-benchmarker/web-frameworks/issues/977...</a><p>Unofficial results (not reliable): <a href="https://github.com/c4punks/CWIST/actions/runs/39000473564/job/117302127557" rel="nofollow">https://github.com/c4punks/CWIST/actions/runs/39000473564/jo...</a><p>Dev blog: <a href="https://oborona.zip" rel="nofollow">https://oborona.zip</a> Org: <a href="https://c4punks.github.io" rel="nofollow">https://c4punks.github.io</a><p>It doesn't help my portfolio, but please star the project if you enjoyed it.<p>Special thanks to <a href="https://github.com/thegoodengineer" rel="nofollow">https://github.com/thegoodengineer</a> for inviting organization members.- 情报分类:工作与职业机会
- 分类依据:内容涉及招聘、求职或职业发展
- 信息来源:Hacker News 新项目
- 发布时间:2026/10/17 14:06:10
- 暂无回复