Skip to content

Commit

Permalink
📦 updates MDK for v0.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
k33g committed Aug 10, 2023
1 parent 0909dcc commit 8ccacd7
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
capsule
capsule-http
site
._.*

4 changes: 2 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ tasks:
#TAG: "v0.0.1"
#TAG: "v0.0.2"
#TAG: "v0.0.4"
TAG: "v0.0.5" # current release
#TAG: "v0.0.6" # it will be the next release
#TAG: "v0.0.5" # current release
TAG: "v0.0.6"

cmds:
- echo "📦 Generating release..."
Expand Down
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Capsule Module SDK

!!! info "What's new?"
- `v0.0.6`: 🐞 Redis fix
- `v0.0.5`: ✨ Add 2 new helpers: `GetHeaders` (transform a JSON string to a map[string]string) and `SetHeaders` (transform a map[string]string to a JSON string)
- `v0.0.4`: ✨ Add the `Success` and `Failure` functions (public functions to call `success` and `failure`) and the `StringifyHTTPResponse` function
- `v0.0.3`: ✨ Encode `retValue.TextBody` to avoid special characters in jsonString
Expand Down
27 changes: 12 additions & 15 deletions hostfunc.memorycache.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func hostCacheSet(
keyPosition, keyLength uint32,
valueStringPosition, valueStringLength uint32,
returnValuePosition **uint32, returnValueLength *uint32) uint32

// CacheSet is an helper to use the hostCacheSet function
func CacheSet(key string, value []byte) []byte {

Expand All @@ -44,22 +44,23 @@ func CacheSet(key string, value []byte) []byte {
&responseBufferPtr, &responseBufferSize)

bufferResponseFromHost := readBufferFromMemory(responseBufferPtr, responseBufferSize)

// check if success or failure
data, _ := Result(bufferResponseFromHost)

return data
}


//export hostCacheGet
func hostCacheGet(
keyPosition, keyLength uint32,
returnValuePosition **uint32, returnValueLength *uint32) uint32

// CacheGet is an helper to use the hostCacheGet function
func CacheGet(key string) ([]byte, error) {

//Log("🦊 THIS IS A TEST")

keyPosition, keyLength := getBufferPosSize([]byte(key))

// This will be use to get the response from the host
Expand All @@ -72,7 +73,7 @@ func CacheGet(key string) ([]byte, error) {
&responseBufferPtr, &responseBufferSize)

bufferResponseFromHost := readBufferFromMemory(responseBufferPtr, responseBufferSize)

// check if success or failure
data, err := Result(bufferResponseFromHost)
if err != nil {
Expand All @@ -81,13 +82,11 @@ func CacheGet(key string) ([]byte, error) {
return data, nil
}



//export hostCacheDel
func hostCacheDel(
keyPosition, keyLength uint32,
returnValuePosition **uint32, returnValueLength *uint32) uint32

// CacheDel is an helper to use the hostCacheDel function
func CacheDel(key string) []byte {

Expand All @@ -103,19 +102,17 @@ func CacheDel(key string) []byte {
&responseBufferPtr, &responseBufferSize)

bufferResponseFromHost := readBufferFromMemory(responseBufferPtr, responseBufferSize)

// check if success or failure
data, _ := Result(bufferResponseFromHost)
return data
}



//export hostCacheKeys
func hostCacheKeys(
filterPosition, filterLength uint32,
returnValuePosition **uint32, returnValueLength *uint32) uint32

// CacheKeys is an helper to use the hostCacheKeys function
func CacheKeys(filter string) ([]string, error) {

Expand All @@ -132,20 +129,20 @@ func CacheKeys(filter string) ([]string, error) {

bufferResponseFromHost := readBufferFromMemory(responseBufferPtr, responseBufferSize)
//! 🤚 this is a json string (array json string: `["Hello", "World"]`)

// check if success or failure
data, err := Result(bufferResponseFromHost)
if err != nil {
return nil, err
}
}
var jsonParser fastjson.Parser
keysArray, err := jsonParser.Parse(string(data))
if err != nil {
return nil, err
}
var keys []string
for _, key := range keysArray.GetArray("keys") {
keys = append(keys, string(key.GetStringBytes()))
keys = append(keys, string(key.GetStringBytes()))
//! if it doesn't work, implement my own simple parser
}
return keys, nil
Expand Down
8 changes: 4 additions & 4 deletions hostfunc.redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func RedisSet(key string, value []byte) ([]byte, error) {
var responseBufferSize uint32

// Send the lessage to the host
hostCacheSet(
hostRedisSet(
keyPosition, keyLength,
valueStringPosition, valueStringLength,
&responseBufferPtr, &responseBufferSize)
Expand Down Expand Up @@ -78,7 +78,7 @@ func RedisGet(key string) ([]byte, error) {
var responseBufferSize uint32

// Send the lessage to the host
hostCacheGet(
hostRedisGet(
keyPosition, keyLength,
&responseBufferPtr, &responseBufferSize)

Expand Down Expand Up @@ -120,7 +120,7 @@ func RedisDel(key string) ([]byte, error) {
var responseBufferSize uint32

// Send the lessage to the host
hostCacheDel(
hostRedisDel(
keyPosition, keyLength,
&responseBufferPtr, &responseBufferSize)

Expand Down Expand Up @@ -157,7 +157,7 @@ func RedisKeys(filter string) ([]string, error) {
var responseBufferSize uint32

// Send the lessage to the host
hostCacheKeys(
hostRedisKeys(
filterPosition, filterLength,
&responseBufferPtr, &responseBufferSize)

Expand Down
2 changes: 2 additions & 0 deletions samples/http-say-hello/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module http-say-hello

go 1.20

require github.com/valyala/fastjson v1.6.4
2 changes: 0 additions & 2 deletions samples/http-say-hello/go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
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=
Binary file added samples/simple.json/._main.go
Binary file not shown.
2 changes: 0 additions & 2 deletions samples/simple/go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
github.com/valyala/fastjson v1.6.4 h1:uAUNq9Z6ymTgGhcm0UynUAB6tlbakBrz6CQFax3BXVQ=
github.com/valyala/fastjson v1.6.4/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=

0 comments on commit 8ccacd7

Please sign in to comment.