Skip to content

Commit

Permalink
📦 updates HDK for v0.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
k33g committed Aug 11, 2023
1 parent bffab37 commit fd84699
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 0 deletions.
12 changes: 12 additions & 0 deletions capsule-cli/functions/redis-db/build.sh
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
1 change: 1 addition & 0 deletions capsule-cli/functions/redis-db/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func main() {
// Handle function
func Handle(params []byte) ([]byte, error) {

capsule.RedisSet("one", []byte("👋"))
capsule.RedisSet("one", []byte("👋"))
capsule.RedisSet("two", []byte("hello"))
capsule.RedisSet("three", []byte("world"))
Expand Down
4 changes: 4 additions & 0 deletions capsule-cli/functions/redis-db/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
REDIS_URI="" \
./capsule --wasm=./redis-db.wasm

1 change: 1 addition & 0 deletions capsule-http/functions/hello-redis-web/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
capsule-http-*
12 changes: 12 additions & 0 deletions capsule-http/functions/hello-redis-web/build.sh
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
9 changes: 9 additions & 0 deletions capsule-http/functions/hello-redis-web/go.mod
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
2 changes: 2 additions & 0 deletions capsule-http/functions/hello-redis-web/go.sum
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=
34 changes: 34 additions & 0 deletions capsule-http/functions/hello-redis-web/main.go
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

})
}
3 changes: 3 additions & 0 deletions capsule-http/functions/hello-redis-web/start.sh
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

0 comments on commit fd84699

Please sign in to comment.