capsule

package module
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2023 License: MIT Imports: 6 Imported by: 0

README

Capsule Module SDK (Capsule MDK)

🚧 this is a work in progress

This SDK allows to create and manage WebAssembly modules for host applications using the Capsule Host Application SDK.

The Capsule Host SDK use the Wazero runtime to run the host application.

Getting started: the capsule plugin

package main

import (
	capsule "github.com/bots-garden/capsule-module-sdk"
)

func main() {
	capsule.SetHandle(Handle)
}

// Handle function
func Handle(param []byte) ([]byte, error) {

	capsule.Log("🟣 from the plugin: " + string(param))
	capsule.Print("💜 from the plugin: " + string(param))

	return []byte("Hello " + string(param)), nil
}

Getting started: the host application

👀 https://github.com/bots-garden/capsule-host-sdk#capsule-host-sdk

Documentation

Overview

Package capsule SDK for WASM plugin

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheDel

func CacheDel(key string) []byte

CacheDel is an helper to use the hostCacheDel function

func CacheGet

func CacheGet(key string) ([]byte, error)

CacheGet is an helper to use the hostCacheGet function

func CacheKeys

func CacheKeys(filter string) ([]string, error)

CacheKeys is an helper to use the hostCacheKeys function

func CacheSet

func CacheSet(key string, value []byte) []byte

CacheSet is an helper to use the hostCacheSet function

func CopyBufferToMemory

func CopyBufferToMemory(buffer []byte) uint64

CopyBufferToMemory returns a single value

func Failure added in v0.0.4

func Failure(buffer []byte) uint64

Failure function

func GetEnv

func GetEnv(variableName string) string

GetEnv is an helper to use the hostGetEnv function

func GetHeaders added in v0.0.5

func GetHeaders(headers string) map[string]string

GetHeaders return a map of headers from a string of headers transform a JSON string to a map[string]string

func Log

func Log(message string)

Log : call host function: hostLogString Print a string

func Print

func Print(message string)

Print : call host function: hostPrintString Print a string

func ReadBufferFromMemory

func ReadBufferFromMemory(bufferPosition *uint32, length uint32) []byte

ReadBufferFromMemory returns a buffer

func ReadFile

func ReadFile(filePath string) ([]byte, error)

ReadFile is an helper to use the hostReadFile function

func RedisDel added in v0.0.2

func RedisDel(key string) ([]byte, error)

RedisDel deletes a Redis key and returns the result as a slice of bytes. The key parameter is a string representing the key to be deleted. The function returns a slice of bytes and an error.

func RedisGet added in v0.0.2

func RedisGet(key string) ([]byte, error)

RedisGet retrieves the value for the given key from Redis.

It takes a single string parameter, `key`, which is used to identify the value to retrieve from Redis.

RedisGet returns a slice of bytes containing the retrieved value, and an error if the retrieval failed or the key was not found.

func RedisKeys added in v0.0.2

func RedisKeys(filter string) ([]string, error)

RedisKeys returns an array of Redis keys that match the given filter.

filter: A string used to filter Redis keys. Returns an array of strings and an error.

func RedisSet added in v0.0.2

func RedisSet(key string, value []byte) ([]byte, error)

RedisSet sends a message to the host to cache a key and its value.

key: the string value of the key to cache. value: the byte slice value to cache. []byte: a byte slice that contains the response from the host.

func Result

func Result(data []byte) ([]byte, error)

Result function

func SetHandle

func SetHandle(function func(param []byte) ([]byte, error))

SetHandle sets the handle function

func SetHandleHTTP

func SetHandleHTTP(function func(param HTTPRequest) (HTTPResponse, error))

SetHandleHTTP sets the handle function

func SetHandleJSON

func SetHandleJSON(function func(param *fastjson.Value) ([]byte, error))

SetHandleJSON sets the handle function

func SetHeaders added in v0.0.5

func SetHeaders(headers map[string]string) string

SetHeaders return a string of headers from a map of headers transform a map[string]string to a JSON string

func StringifyHTTPResponse added in v0.0.4

func StringifyHTTPResponse(response HTTPResponse) string

StringifyHTTPResponse converts a HTTPResponse to a string

func Success added in v0.0.4

func Success(buffer []byte) uint64

Success function

func Talk

func Talk(bufferMessageToHost []byte) []byte

Talk is an helper to use the hostTalk function

func WriteFile

func WriteFile(filePath string, content []byte) error

WriteFile is an helper to use the hostWriteFile function

Types

type HTTPRequest

type HTTPRequest struct {
	Body     string
	JSONBody string
	TextBody string
	URI      string
	Method   string
	Headers  string
}

HTTPRequest is the data of the http request

type HTTPResponse

type HTTPResponse struct {
	//Body    string
	JSONBody   string
	TextBody   string
	Headers    string
	StatusCode int
}

HTTPResponse is the data of the http response

func HTTP

func HTTP(request HTTPRequest) (HTTPResponse, error)

HTTP is an helper to use the hostHTTP function

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL