Skip to content

Commit 10a566a

Browse files
Merge pull request #295 from appwrite/feat-go-starter
Feat: Go starter
2 parents fadd090 + 6e77970 commit 10a566a

File tree

6 files changed

+101
-0
lines changed

6 files changed

+101
-0
lines changed

.github/workflows/markdown-table-workflow/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from "node:path";
33
import { markdownTable } from "markdown-table";
44

55
const verboseRuntimes = {
6+
go: "Go",
67
cpp: "C++",
78
dart: "Dart",
89
deno: "Deno",

go/starter/.prettierrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"trailingComma": "es5",
3+
"tabWidth": 2,
4+
"semi": true,
5+
"singleQuote": true
6+
}

go/starter/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# ⚡ Go Starter Function
2+
3+
A simple starter function. Edit `src/main.go` to get started and create something awesome! 🚀
4+
5+
## 🧰 Usage
6+
7+
### GET /
8+
9+
- Returns a "Hello, World!" message.
10+
11+
**Response**
12+
13+
Sample `200` Response:
14+
15+
```text
16+
Hello, World!
17+
```
18+
19+
### POST, PUT, PATCH, DELETE /
20+
21+
- Returns a "Learn More" JSON response.
22+
23+
**Response**
24+
25+
Sample `200` Response:
26+
27+
```json
28+
{
29+
"motto": "Build like a team of hundreds_",
30+
"learn": "https://appwrite.io/docs",
31+
"connect": "https://appwrite.io/discord",
32+
"getInspired": "https://builtwith.appwrite.io"
33+
}
34+
```
35+
36+
## ⚙️ Configuration
37+
38+
| Setting | Value |
39+
| ----------------- | ------------- |
40+
| Runtime | Go (1.22) |
41+
| Entrypoint | `src/main.go` |
42+
| Permissions | `any` |
43+
| Timeout (Seconds) | 15 |
44+
45+
## 🔒 Environment Variables
46+
47+
No environment variables required.

go/starter/go.mod

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module openruntimes/handler
2+
3+
go 1.22.5
4+
5+
require github.com/open-runtimes/types-for-go/v4 v4.0.1
6+
require github.com/appwrite/sdk-for-go v0.0.1-rc.1

go/starter/go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
github.com/appwrite/sdk-for-go v0.0.1-rc.1 h1:OgKS/OCMpDPBrcIo1KsSNMhUmTDQ5n/tppTPzcNPIb8=
2+
github.com/appwrite/sdk-for-go v0.0.1-rc.1/go.mod h1:lLim0S47hdXlLet+GAayvBC7VfVxcsoSZ1F5oymXrmc=
3+
github.com/open-runtimes/types-for-go/v4 v4.0.1 h1:DRPNvUJl3yiiDFUxfs3AqToE78PTmr6KZxJdeCVZbdo=
4+
github.com/open-runtimes/types-for-go/v4 v4.0.1/go.mod h1:88UUMYovXGRbv5keL4uTKDYMWeNtIKV0BbxDRQ18/xY=

go/starter/main.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package handler
2+
3+
import (
4+
"github.com/open-runtimes/types-for-go/v4"
5+
)
6+
7+
// This is your Appwrite function
8+
// It's executed each time we get a request
9+
func Main(Context *types.Context) types.ResponseOutput {
10+
// Why not try the Appwrite SDK?
11+
//
12+
// appwriteClient := client.NewClient()
13+
// appwriteClient.SetEndpoint(os.Getenv("APPWRITE_FUNCTION_API_ENDPOINT"))
14+
// appwriteClient.SetProject(os.Getenv("APPWRITE_FUNCTION_PROJECT_ID"))
15+
// appwriteClient.SetKey(Context.Req.Headers["x-appwrite-key"])
16+
17+
// You can log messages to the console
18+
Context.Log("Hello, Logs!")
19+
20+
// If something goes wrong, log an error
21+
Context.Error("Hello, Errors!")
22+
23+
// The `Req` object contains the request data
24+
if Context.Req.Method == "GET" {
25+
// Send a text response with the res object helpers
26+
// `Res.Text()` dispatches a string back to the client
27+
return Context.Res.Text("Hello, World!", 200, nil)
28+
}
29+
30+
// `Res.Json()` is a handy helper for sending JSON
31+
return Context.Res.Json(map[string]interface{}{
32+
"motto": "Build like a team of hundreds_",
33+
"learn": "https://appwrite.io/docs",
34+
"connect": "https://appwrite.io/discord",
35+
"getInspired": "https://builtwith.appwrite.io",
36+
}, 200, nil)
37+
}

0 commit comments

Comments
 (0)