Skip to content

Commit a425f0b

Browse files
committed
📦 updates HDK for v0.0.2
1 parent 7105616 commit a425f0b

27 files changed

+646
-90
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ host
33
simple-host
44
simple-hello-host
55
simple-talk-host
6+
cracke/cracker
67
*.wasm
78
site

Taskfile.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ tasks:
2121
release:
2222
env:
2323
#TAG: "v0.0.1"
24-
TAG: "v0.0.2" # next release
24+
TAG: "v0.0.2"
25+
#TAG: "v0.0.3" # next release
2526
cmds:
2627
- echo "📦 Generating release..."
2728
- git add .

capsule.dk.go

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,59 @@ import (
1010
const isFailure = rune('F')
1111
const isSuccess = rune('S')
1212

13-
/*
14-
func main() {
15-
panic("not implemented")
16-
}
17-
18-
func success(buffer []byte) uint64 {
19-
return copyBufferToMemory(append([]byte(string(isSuccess)), buffer...))
20-
}
21-
22-
func failure(buffer []byte) uint64 {
23-
return copyBufferToMemory(append([]byte(string(isFailure)), buffer...))
24-
}
25-
*/
26-
13+
// success appends the isSuccess byte to the beginning of the input buffer and returns the result.
14+
//
15+
// buffer: byte slice to append isSuccess byte to.
16+
// []byte: byte slice with the appended isSuccess byte.
2717
func success(buffer []byte) []byte {
2818
return append([]byte(string(isSuccess)), buffer...)
2919
}
3020

21+
// failure appends a string "isFailure" to the given byte slice buffer and returns the new slice.
22+
//
23+
// buffer: the byte slice to which "isFailure" is appended.
24+
// Returns the new byte slice with the string "isFailure" appended to it.
3125
func failure(buffer []byte) []byte {
3226
return append([]byte(string(isFailure)), buffer...)
3327
}
3428

35-
36-
37-
38-
// Result function
29+
// Result returns the data without the first byte if the first byte is isSuccess.
30+
// Otherwise, it returns nil and an error with the data starting from the second byte.
31+
//
32+
// data: A byte slice containing the data to check.
33+
// []byte: The data without the first byte if the first byte is isSuccess.
34+
// error: If the first byte is not isSuccess, it returns an error with the data starting from the second byte.
3935
func Result(data []byte,) ([]byte, error) {
4036
if data[0] == byte(isSuccess) {
4137
return data[1:], nil
4238
}
4339
return nil, errors.New(string(data[1:]))
4440
}
4541

46-
// GetHandle returns the handle function
42+
// GetHandle returns an exported function named "callHandle" from the given module.
43+
//
44+
// mod: The module to retrieve the function from.
45+
//
46+
// Returns: An exported function with the name "callHandle".
4747
func GetHandle(mod api.Module) api.Function {
4848
return mod.ExportedFunction("callHandle")
4949
}
5050

51-
// GetHandleJSON returns the handle function
51+
// GetHandleJSON returns the exported "callHandleJSON" function from the given module.
52+
//
53+
// mod: the module to retrieve the function from.
54+
//
55+
// returns: the exported "callHandleJSON" function.
5256
func GetHandleJSON(mod api.Module) api.Function {
5357
return mod.ExportedFunction("callHandleJSON")
5458
}
5559

56-
// GetHandleHTTP returns the handle function
60+
// GetHandleHTTP returns the exported 'callHandleHTTP' function from a given module.
61+
//
62+
// mod: The module containing the exported function.
63+
//
64+
// returns:
65+
// - api.Function: the exported 'callHandleHTTP' function.
5766
func GetHandleHTTP(mod api.Module) api.Function {
5867
return mod.ExportedFunction("callHandleHTTP")
5968
}
60-
61-
// TODO: handle the other handles

docs/getting-started.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,3 @@
44
55
## Create a Capsule application
66

7-
Create a directory `say-hello`
8-
9-
```bash
10-
mkdir say-hello
11-
cd say-hello
12-
```
13-
14-
Initialize a new project in `say-hello`:
15-
16-
```bash
17-
go mod init say-hello
18-
```
19-
20-
Install the Capsule **HDK** dependencies:
21-
```bash
22-
go get github.com/bots-garden/capsule-host-sdk
23-
```

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Capsule Host SDK
22

33
!!! info "What's new?"
4+
- `v0.0.2`: ✨ Redis support
45
- `v0.0.1`: 🎉 first release
56

67
## What is the Capsule Host SDK alias **Capsule HDK**?

go.mod

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@ require (
77
github.com/tetratelabs/wazero v1.1.0
88
)
99

10-
require golang.org/x/net v0.0.0-20211029224645-99673261e6eb // indirect
10+
require (
11+
github.com/cespare/xxhash/v2 v2.2.0 // indirect
12+
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
13+
github.com/redis/go-redis/v9 v9.0.4 // indirect
14+
golang.org/x/net v0.0.0-20211029224645-99673261e6eb // indirect
15+
)

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
2+
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
3+
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
4+
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
15
github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPrFY=
26
github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I=
7+
github.com/redis/go-redis/v9 v9.0.4 h1:FC82T+CHJ/Q/PdyLW++GeCO+Ol59Y4T7R4jbgjvktgc=
8+
github.com/redis/go-redis/v9 v9.0.4/go.mod h1:WqMKv5vnQbRuZstUwxQI195wHy+t4PuXDOjzMvcuQHk=
39
github.com/tetratelabs/wazero v1.1.0 h1:EByoAhC+QcYpwSZJSs/aV0uokxPwBgKxfiokSUwAknQ=
410
github.com/tetratelabs/wazero v1.1.0/go.mod h1:wYx2gNRg8/WihJfSDxA1TIL8H+GkfLYm+bIfbblu9VQ=
511
golang.org/x/net v0.0.0-20211029224645-99673261e6eb h1:pirldcYWx7rx7kE5r+9WsOXPXK0+WH5+uZ7uPmJ44uM=

go.work

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ use (
44
./samples/simple
55
./samples/simple-hello
66
./samples/simple-talk
7+
./samples/cracker
78
)

go.work.sum

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
2+
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
3+
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
4+
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
5+
github.com/redis/go-redis/v9 v9.0.4 h1:FC82T+CHJ/Q/PdyLW++GeCO+Ol59Y4T7R4jbgjvktgc=
6+
github.com/redis/go-redis/v9 v9.0.4/go.mod h1:WqMKv5vnQbRuZstUwxQI195wHy+t4PuXDOjzMvcuQHk=
17
github.com/tetratelabs/wazero v1.0.1 h1:xyWBoGyMjYekG3mEQ/W7xm9E05S89kJ/at696d/9yuc=
28
github.com/tetratelabs/wazero v1.0.1/go.mod h1:wYx2gNRg8/WihJfSDxA1TIL8H+GkfLYm+bIfbblu9VQ=
3-
github.com/tetratelabs/wazero v1.1.0 h1:EByoAhC+QcYpwSZJSs/aV0uokxPwBgKxfiokSUwAknQ=
4-
github.com/tetratelabs/wazero v1.1.0/go.mod h1:wYx2gNRg8/WihJfSDxA1TIL8H+GkfLYm+bIfbblu9VQ=
59
github.com/valyala/fastjson v1.6.4/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=

hostfunc.envvar.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package capsule
22

3-
// this hostfunction is a template for the other host functions
43
import (
54
"context"
65
"log"
@@ -10,7 +9,12 @@ import (
109
"github.com/tetratelabs/wazero/api"
1110
)
1211

13-
// DefineHostFuncGetEnv defines a host function allowing the wasm guest to get an environment variable by name
12+
// DefineHostFuncGetEnv defines a new host function to get the environment variable value.
13+
//
14+
// Parameters:
15+
// - builder: the HostModuleBuilder to add the function to.
16+
//
17+
// Returns: nothing.
1418
func DefineHostFuncGetEnv(builder wazero.HostModuleBuilder) {
1519
builder.NewFunctionBuilder().
1620
WithGoModuleFunction(getEnv,

0 commit comments

Comments
 (0)