-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #295 from appwrite/feat-go-starter
Feat: Go starter
- Loading branch information
Showing
6 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"trailingComma": "es5", | ||
"tabWidth": 2, | ||
"semi": true, | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |