-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
121 additions
and
17 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
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,65 @@ | ||
# 🧰 Helpers | ||
|
||
> 🚧 this is a work in progress | ||
## Success and Failure | ||
> introduced in v0.0.4 | ||
`Success` and `Failure` copy an `[]byte` to the shared memory, and return the position and the length of the value "packed" into a single value (`uint64`). | ||
|
||
If you use `Success`, the `[]byte` is prefixed by `rune('S')` before being copied to the shared memory. | ||
|
||
If you use `Failure`, the `[]byte` is prefixed by `rune('F')` before being copied to the shared memory. | ||
|
||
This value will be used by the function `CallHandleFunction` of the [Host SDK](https://github.com/bots-garden/capsule-host-sdk/blob/main/runtime.go) that will use the [`Result` function](https://github.com/bots-garden/capsule-host-sdk/blob/main/capsule.dk.go) to extract the result status (success or failure) and the result value (value or error). | ||
|
||
```golang | ||
// Package main | ||
package main | ||
|
||
import ( | ||
"strconv" | ||
"github.com/bots-garden/capsule-module-sdk" | ||
) | ||
|
||
// OnHealthCheck function | ||
//export OnHealthCheck | ||
func OnHealthCheck() uint64 { | ||
capsule.Print("⛑️ OnHealthCheck") | ||
|
||
response := capsule.HTTPResponse{ | ||
JSONBody: `{"message": "OK"}`, | ||
Headers: `{"Content-Type": "application/json; charset=utf-8"}`, | ||
StatusCode: 200, | ||
} | ||
|
||
return capsule.Success([]byte(capsule.StringifyHTTPResponse(response))) | ||
} | ||
|
||
func main() { | ||
capsule.SetHandleHTTP(func (param capsule.HTTPRequest) (capsule.HTTPResponse, error) { | ||
return capsule.HTTPResponse{ | ||
TextBody: "👋 Hey", | ||
Headers: `{"Content-Type": "text/plain; charset=utf-8"}`, | ||
StatusCode: 200, | ||
}, nil | ||
|
||
}) | ||
} | ||
``` | ||
> 👋 don't forget to export the `OnHealthCheck` function | ||
## StringifyHTTPResponse | ||
> introduced in v0.0.4 | ||
`StringifyHTTPResponse` converts a `capsule.HTTPResponse` into a string. | ||
|
||
```golang | ||
response := capsule.HTTPResponse{ | ||
JSONBody: `{"message": "OK"}`, | ||
Headers: `{"Content-Type": "application/json; charset=utf-8"}`, | ||
StatusCode: 200, | ||
} | ||
|
||
str := capsule.StringifyHTTPResponse(response) | ||
``` |
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
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,4 @@ | ||
github.com/bots-garden/capsule-module-sdk v0.0.3 h1:a0TRgwdiJjc+9raOe4zQoWPnzxKegqmInVmwzlaDuug= | ||
github.com/bots-garden/capsule-module-sdk v0.0.3/go.mod h1:DtKYwanz4YvBwSpu0GuuhtkeFE6+jDgEucBOTWVBMy8= | ||
github.com/valyala/fastjson v1.6.4 h1:uAUNq9Z6ymTgGhcm0UynUAB6tlbakBrz6CQFax3BXVQ= | ||
github.com/valyala/fastjson v1.6.4/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY= |
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