Skip to content

Commit

Permalink
Merge pull request #295 from appwrite/feat-go-starter
Browse files Browse the repository at this point in the history
Feat: Go starter
  • Loading branch information
TorstenDittmann authored Jul 4, 2024
2 parents fadd090 + 6e77970 commit 10a566a
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/markdown-table-workflow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from "node:path";
import { markdownTable } from "markdown-table";

const verboseRuntimes = {
go: "Go",
cpp: "C++",
dart: "Dart",
deno: "Deno",
Expand Down
6 changes: 6 additions & 0 deletions go/starter/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": true,
"singleQuote": true
}
47 changes: 47 additions & 0 deletions go/starter/README.md
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 6 additions & 0 deletions go/starter/go.mod
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions go/starter/go.sum
Original file line number Diff line number Diff line change
@@ -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=
37 changes: 37 additions & 0 deletions go/starter/main.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 10a566a

Please sign in to comment.