From 8ccacd701efb1b0e1726e8602c6c63029732ae31 Mon Sep 17 00:00:00 2001 From: k33g Date: Thu, 10 Aug 2023 07:12:40 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A6=20updates=20MDK=20for=20v0.0.6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + Taskfile.yml | 4 ++-- docs/index.md | 1 + hostfunc.memorycache.go | 27 ++++++++++++--------------- hostfunc.redis.go | 8 ++++---- samples/http-say-hello/go.mod | 2 ++ samples/http-say-hello/go.sum | 2 -- samples/simple.json/._main.go | Bin 0 -> 4096 bytes samples/simple/go.sum | 2 -- 9 files changed, 22 insertions(+), 25 deletions(-) create mode 100644 samples/simple.json/._main.go diff --git a/.gitignore b/.gitignore index 373bf9c..db86441 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ capsule capsule-http site +._.* diff --git a/Taskfile.yml b/Taskfile.yml index 5a49cd4..7bb768b 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -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..." diff --git a/docs/index.md b/docs/index.md index bae970e..d88ba17 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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 diff --git a/hostfunc.memorycache.go b/hostfunc.memorycache.go index f260f8a..ebc2a05 100644 --- a/hostfunc.memorycache.go +++ b/hostfunc.memorycache.go @@ -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 { @@ -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 @@ -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 { @@ -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 { @@ -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) { @@ -132,12 +129,12 @@ 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 { @@ -145,7 +142,7 @@ func CacheKeys(filter string) ([]string, error) { } 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 diff --git a/hostfunc.redis.go b/hostfunc.redis.go index 3fb5cca..82607dd 100644 --- a/hostfunc.redis.go +++ b/hostfunc.redis.go @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/samples/http-say-hello/go.mod b/samples/http-say-hello/go.mod index 46744bd..42d0fbb 100644 --- a/samples/http-say-hello/go.mod +++ b/samples/http-say-hello/go.mod @@ -1,3 +1,5 @@ module http-say-hello go 1.20 + +require github.com/valyala/fastjson v1.6.4 diff --git a/samples/http-say-hello/go.sum b/samples/http-say-hello/go.sum index a96e182..d0e4603 100644 --- a/samples/http-say-hello/go.sum +++ b/samples/http-say-hello/go.sum @@ -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= diff --git a/samples/simple.json/._main.go b/samples/simple.json/._main.go new file mode 100644 index 0000000000000000000000000000000000000000..948e79ddba14bda200482f565df1bae920200336 GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vV$ix_ z2GPN=0H|C5O$#HC4;7b6&d=3LEGWoH)yqjNE-5WeO-V^CNmULA2I<+q)Hwx2ztCN0 z45CNDXb6mkz-S1JhQMeDjE2By2#kinXb6mkz-S1JhQMeD;0ggyXA^|MKrSRBvsj@h zwK%`DC^=OjEx#yRAv3QeHLoNyKQA#Sr&1v&HLXM;DJL;68`u|y>Kf7%s{i3$kztVg G{~rK~g)2A! literal 0 HcmV?d00001 diff --git a/samples/simple/go.sum b/samples/simple/go.sum index d0e4603..e69de29 100644 --- a/samples/simple/go.sum +++ b/samples/simple/go.sum @@ -1,2 +0,0 @@ -github.com/valyala/fastjson v1.6.4 h1:uAUNq9Z6ymTgGhcm0UynUAB6tlbakBrz6CQFax3BXVQ= -github.com/valyala/fastjson v1.6.4/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=