From caa342e09de58ed611790c05de67b9a1b7a43582 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 21 Jul 2023 16:18:09 +0100 Subject: [PATCH 1/4] feat: C++ starter --- cpp/.gitignore | 32 ++++++++++++++++++++++++++++++++ cpp/README.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ cpp/src/main.cc | 30 ++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 cpp/.gitignore create mode 100644 cpp/README.md create mode 100644 cpp/src/main.cc diff --git a/cpp/.gitignore b/cpp/.gitignore new file mode 100644 index 00000000..d99efa91 --- /dev/null +++ b/cpp/.gitignore @@ -0,0 +1,32 @@ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app \ No newline at end of file diff --git a/cpp/README.md b/cpp/README.md new file mode 100644 index 00000000..d4894f0a --- /dev/null +++ b/cpp/README.md @@ -0,0 +1,48 @@ +# ⚡ C++ Starter Function + +A simple starter function. Edit `src/main.cc` to get started and create something awesome! 🚀 + +## 🧰 Usage + +### `GET` + +- Returns a "Hello, World!" message. + +**Response** + +Sample `200` Response: + +```text +Hello, World! 🌎 +``` + +### `POST`, `PUT`, `PATCH`, `DELETE` + +- Returns a "Learn More" JSON response. + +**Response** + +Sample `200` Response: + +```json +{ + "motto": "Build Fast. Scale Big. All in One Place.", + "learn": "https://appwrite.io/docs", + "connect": "https://appwrite.io/discord", + "getInspired": "https://builtwith.appwrite.io" +} +``` + +## ⚙️ Configuration + +| Setting | Value | +|-------------------|--------------------| +| Runtime | C++ (17) | +| Entrypoint | `src/main.cc` | +| Build Commands | | +| Permissions | `any` | +| Timeout (Seconds) | 15 | + +## 🔒 Environment Variables + +No environment variables required. diff --git a/cpp/src/main.cc b/cpp/src/main.cc new file mode 100644 index 00000000..12ac1dab --- /dev/null +++ b/cpp/src/main.cc @@ -0,0 +1,30 @@ +namespace runtime { +class Handler { +public: + // This is your Appwrite function + // It's executed each time we get a request + static RuntimeOutput main(RuntimeContext &context) { + // You can log messages to the console + context.log("Hello, Logs! 👋"); + + // If something goes wrong, log an error + context.log("Hello, Errors! ⛔"); + + // The `req` object contains the request data + if (context.req.method == "GET") { + // Send a response with the res object helpers + // `context.res.send()` dispatches a string back to the client + return context.res.send("Hello, World! 🌎"); + } + + // `context.res.json()` is a handy helper for sending JSON + Json::Value response; + response['motto'] = "Build Fast. Scale Big. All in One Place."; + response['learn'] = "https://appwrite.io/docs"; + response['connect'] = "https://appwrite.io/discord"; + response['getInspired'] = "https://builtwith.appwrite.io"; + + return context.res.json(response); + } +}; +} // namespace runtime \ No newline at end of file From 723dafaf3d0a65e8b2ccbaacb27d45bcb3ac1036 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 21 Jul 2023 19:20:45 +0100 Subject: [PATCH 2/4] chore: remove random comment --- cpp/src/main.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/main.cc b/cpp/src/main.cc index 12ac1dab..db9aafb9 100644 --- a/cpp/src/main.cc +++ b/cpp/src/main.cc @@ -27,4 +27,4 @@ class Handler { return context.res.json(response); } }; -} // namespace runtime \ No newline at end of file +} \ No newline at end of file From 6b997ae25f20d5c83b2d2019cff1cd4d6109ef15 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 21 Jul 2023 19:21:08 +0100 Subject: [PATCH 3/4] docs: remove build command for cpp --- cpp/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/cpp/README.md b/cpp/README.md index d4894f0a..394c6707 100644 --- a/cpp/README.md +++ b/cpp/README.md @@ -39,7 +39,6 @@ Sample `200` Response: |-------------------|--------------------| | Runtime | C++ (17) | | Entrypoint | `src/main.cc` | -| Build Commands | | | Permissions | `any` | | Timeout (Seconds) | 15 | From 62ffef89ee00a43cee4c25a9647d272ce8fb2059 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Sat, 22 Jul 2023 09:58:31 +0100 Subject: [PATCH 4/4] chore: fmt --- cpp/src/main.cc | 51 ++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/cpp/src/main.cc b/cpp/src/main.cc index db9aafb9..72932643 100644 --- a/cpp/src/main.cc +++ b/cpp/src/main.cc @@ -1,30 +1,29 @@ namespace runtime { -class Handler { -public: - // This is your Appwrite function - // It's executed each time we get a request - static RuntimeOutput main(RuntimeContext &context) { - // You can log messages to the console - context.log("Hello, Logs! 👋"); + class Handler { + public: + // This is your Appwrite function + // It's executed each time we get a request + static RuntimeOutput main(RuntimeContext &context) { + // You can log messages to the console + context.log("Hello, Logs! 👋"); - // If something goes wrong, log an error - context.log("Hello, Errors! ⛔"); + // If something goes wrong, log an error + context.log("Hello, Errors! ⛔"); - // The `req` object contains the request data - if (context.req.method == "GET") { - // Send a response with the res object helpers - // `context.res.send()` dispatches a string back to the client - return context.res.send("Hello, World! 🌎"); - } + // The `req` object contains the request data + if (context.req.method == "GET") { + // Send a response with the res object helpers + // `context.res.send()` dispatches a string back to the client + return context.res.send("Hello, World! 🌎"); + } - // `context.res.json()` is a handy helper for sending JSON - Json::Value response; - response['motto'] = "Build Fast. Scale Big. All in One Place."; - response['learn'] = "https://appwrite.io/docs"; - response['connect'] = "https://appwrite.io/discord"; - response['getInspired'] = "https://builtwith.appwrite.io"; - - return context.res.json(response); - } -}; -} \ No newline at end of file + // `context.res.json()` is a handy helper for sending JSON + Json::Value response; + response['motto'] = "Build Fast. Scale Big. All in One Place."; + response['learn'] = "https://appwrite.io/docs"; + response['connect'] = "https://appwrite.io/discord"; + response['getInspired'] = "https://builtwith.appwrite.io"; + return context.res.json(response); + } + }; +}