From 6e7797021155cb7bf10999dcb701bed2809d954e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Thu, 4 Jul 2024 10:18:43 +0000 Subject: [PATCH] Go starter --- .../markdown-table-workflow/index.js | 1 + go/starter/.prettierrc.json | 6 +++ go/starter/README.md | 47 +++++++++++++++++++ go/starter/go.mod | 6 +++ go/starter/go.sum | 4 ++ go/starter/main.go | 37 +++++++++++++++ 6 files changed, 101 insertions(+) create mode 100644 go/starter/.prettierrc.json create mode 100644 go/starter/README.md create mode 100644 go/starter/go.mod create mode 100644 go/starter/go.sum create mode 100644 go/starter/main.go diff --git a/.github/workflows/markdown-table-workflow/index.js b/.github/workflows/markdown-table-workflow/index.js index b8965031..eb666b4c 100644 --- a/.github/workflows/markdown-table-workflow/index.js +++ b/.github/workflows/markdown-table-workflow/index.js @@ -3,6 +3,7 @@ import path from "node:path"; import { markdownTable } from "markdown-table"; const verboseRuntimes = { + go: "Go", cpp: "C++", dart: "Dart", deno: "Deno", diff --git a/go/starter/.prettierrc.json b/go/starter/.prettierrc.json new file mode 100644 index 00000000..0a725205 --- /dev/null +++ b/go/starter/.prettierrc.json @@ -0,0 +1,6 @@ +{ + "trailingComma": "es5", + "tabWidth": 2, + "semi": true, + "singleQuote": true +} diff --git a/go/starter/README.md b/go/starter/README.md new file mode 100644 index 00000000..215b760a --- /dev/null +++ b/go/starter/README.md @@ -0,0 +1,47 @@ +# ⚡ Go Starter Function + +A simple starter function. Edit `src/main.go` 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 like a team of hundreds_", + "learn": "https://appwrite.io/docs", + "connect": "https://appwrite.io/discord", + "getInspired": "https://builtwith.appwrite.io" +} +``` + +## ⚙️ Configuration + +| Setting | Value | +| ----------------- | ------------- | +| Runtime | Go (1.22) | +| Entrypoint | `src/main.go` | +| Permissions | `any` | +| Timeout (Seconds) | 15 | + +## 🔒 Environment Variables + +No environment variables required. diff --git a/go/starter/go.mod b/go/starter/go.mod new file mode 100644 index 00000000..36220171 --- /dev/null +++ b/go/starter/go.mod @@ -0,0 +1,6 @@ +module openruntimes/handler + +go 1.22.5 + +require github.com/open-runtimes/types-for-go/v4 v4.0.1 +require github.com/appwrite/sdk-for-go v0.0.1-rc.1 diff --git a/go/starter/go.sum b/go/starter/go.sum new file mode 100644 index 00000000..b61a4240 --- /dev/null +++ b/go/starter/go.sum @@ -0,0 +1,4 @@ +github.com/appwrite/sdk-for-go v0.0.1-rc.1 h1:OgKS/OCMpDPBrcIo1KsSNMhUmTDQ5n/tppTPzcNPIb8= +github.com/appwrite/sdk-for-go v0.0.1-rc.1/go.mod h1:lLim0S47hdXlLet+GAayvBC7VfVxcsoSZ1F5oymXrmc= +github.com/open-runtimes/types-for-go/v4 v4.0.1 h1:DRPNvUJl3yiiDFUxfs3AqToE78PTmr6KZxJdeCVZbdo= +github.com/open-runtimes/types-for-go/v4 v4.0.1/go.mod h1:88UUMYovXGRbv5keL4uTKDYMWeNtIKV0BbxDRQ18/xY= diff --git a/go/starter/main.go b/go/starter/main.go new file mode 100644 index 00000000..d9fa5f48 --- /dev/null +++ b/go/starter/main.go @@ -0,0 +1,37 @@ +package handler + +import ( + "github.com/open-runtimes/types-for-go/v4" +) + +// This is your Appwrite function +// It's executed each time we get a request +func Main(Context *types.Context) types.ResponseOutput { + // Why not try the Appwrite SDK? + // + // appwriteClient := client.NewClient() + // appwriteClient.SetEndpoint(os.Getenv("APPWRITE_FUNCTION_API_ENDPOINT")) + // appwriteClient.SetProject(os.Getenv("APPWRITE_FUNCTION_PROJECT_ID")) + // appwriteClient.SetKey(Context.Req.Headers["x-appwrite-key"]) + + // You can log messages to the console + Context.Log("Hello, Logs!") + + // If something goes wrong, log an error + Context.Error("Hello, Errors!") + + // The `Req` object contains the request data + if Context.Req.Method == "GET" { + // Send a text response with the res object helpers + // `Res.Text()` dispatches a string back to the client + return Context.Res.Text("Hello, World!", 200, nil) + } + + // `Res.Json()` is a handy helper for sending JSON + return Context.Res.Json(map[string]interface{}{ + "motto": "Build like a team of hundreds_", + "learn": "https://appwrite.io/docs", + "connect": "https://appwrite.io/discord", + "getInspired": "https://builtwith.appwrite.io", + }, 200, nil) +}