-
Notifications
You must be signed in to change notification settings - Fork 8
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
9 changed files
with
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
tinygo build -o redis-db.wasm \ | ||
-scheduler=none \ | ||
--no-debug \ | ||
-target wasi ./main.go | ||
ls -lh *.wasm | ||
|
||
echo "📦 Building capsule-cli..." | ||
cd ../.. | ||
go build -ldflags="-s -w" -o capsule | ||
ls -lh capsule | ||
mv capsule ./functions/redis-db |
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 @@ | ||
#!/bin/bash | ||
REDIS_URI="" \ | ||
./capsule --wasm=./redis-db.wasm | ||
|
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 @@ | ||
capsule-http-* |
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,12 @@ | ||
#!/bin/bash | ||
tinygo build -o hello-redis-web.wasm \ | ||
-scheduler=none \ | ||
--no-debug \ | ||
-target wasi ./main.go | ||
ls -lh *.wasm | ||
|
||
echo "📦 Building capsule-http..." | ||
cd ../.. | ||
go build -ldflags="-s -w" -o capsule-http | ||
ls -lh capsule-http | ||
mv capsule-http ./functions/hello-redis-web |
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,9 @@ | ||
module hello-redis-web | ||
|
||
go 1.20 | ||
|
||
require github.com/bots-garden/capsule-module-sdk v0.0.6 | ||
|
||
require github.com/valyala/fastjson v1.6.4 // indirect | ||
|
||
replace github.com/bots-garden/capsule-module-sdk => ../../../../capsule-module-sdk |
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,2 @@ | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Package main | ||
package main | ||
|
||
import ( | ||
//"errors" | ||
|
||
"errors" | ||
|
||
"github.com/bots-garden/capsule-module-sdk" | ||
) | ||
|
||
func main() { | ||
|
||
capsule.SetHandleHTTP(func(param capsule.HTTPRequest) (capsule.HTTPResponse, error) { | ||
|
||
// get values from Redis | ||
message, errMsg := capsule.RedisGet("message") | ||
xHandle, errHandle := capsule.RedisGet("x_handle") | ||
errs := errors.Join(errMsg, errHandle) | ||
|
||
if errs != nil { | ||
capsule.Log("😡 " + errs.Error()) | ||
} | ||
|
||
response := capsule.HTTPResponse{ | ||
JSONBody: `{"message": "` + string(message) + `", "xHandle": "` + string(xHandle) + `"}`, | ||
Headers: `{"Content-Type": "application/json; charset=utf-8"}`, | ||
StatusCode: 200, | ||
} | ||
|
||
return response, errs | ||
|
||
}) | ||
} |
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,3 @@ | ||
#!/bin/bash | ||
REDIS_URI="" \ | ||
./capsule-http --wasm=./hello-redis-web.wasm --httpPort=8080 |