Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var CouchBaseQuery = api.GoModuleFunc(func(ctx context.Context, module api.Module, stack []uint64) { InitCouchBaseCluster() queryPosition := uint32(stack[0]) queryLength := uint32(stack[1]) queryStr := memory.ReadStringFromMemory(ctx, module, queryPosition, queryLength) queryResults, err := getCouchBaseCluster().Query(queryStr, nil) var stringResultFromHost = "" var records []map[string]interface{} var record interface{} if err != nil { log.Fatalf("%v", err) } for queryResults.Next() { err := queryResults.Row(&record) if err != nil { panic(err) } records = append(records, record.(map[string]interface{})) } jsonStringArray, _ := json.Marshal(records) if err != nil { stringResultFromHost = commons.CreateStringError(err.Error(), 0) } else { stringResultFromHost = string(jsonStringArray) if len(stringResultFromHost) == 0 { stringResultFromHost = "empty" } } positionReturnBuffer := uint32(stack[2]) lengthReturnBuffer := uint32(stack[3]) memory.WriteStringToMemory(stringResultFromHost, ctx, module, positionReturnBuffer, lengthReturnBuffer) stack[0] = 0 })
CouchBaseQuery : The wasm module will call this function like this: `func CouchBaseQuery(query string) (string, error)`
var GetEnv = api.GoModuleFunc(func(ctx context.Context, module api.Module, stack []uint64) { positionVariableName := uint32(stack[0]) lengthVariableName := uint32(stack[1]) variableName := memory.ReadStringFromMemory(ctx, module, positionVariableName, lengthVariableName) var stringResultFromHost = "" variableValue := os.Getenv(variableName) if variableValue == "" { stringResultFromHost = commons.CreateStringError(variableName+" is empty", 0) } else { stringResultFromHost = variableValue } positionReturnBuffer := uint32(stack[2]) lengthReturnBuffer := uint32(stack[3]) memory.WriteStringToMemory(stringResultFromHost, ctx, module, positionReturnBuffer, lengthReturnBuffer) stack[0] = 0 })
GetEnv : The wasm module will call this function like this: `func GetEnv(param string) (string, error)`
var GetExitCode = api.GoModuleFunc(func(ctx context.Context, module api.Module, stack []uint64) { exitCode := strconv.Itoa(commons.GetExitCode()) retBuffPtrPos := uint32(stack[0]) retBuffSize := uint32(stack[1]) memory.WriteStringToMemory(exitCode, ctx, module, retBuffPtrPos, retBuffSize) stack[0] = 0 })
var GetExitError = api.GoModuleFunc(func(ctx context.Context, module api.Module, stack []uint64) { exitError := commons.GetExitError() retBuffPtrPos := uint32(stack[0]) retBuffSize := uint32(stack[1]) memory.WriteStringToMemory(exitError, ctx, module, retBuffPtrPos, retBuffSize) stack[0] = 0 })
var GetHostInformation = api.GoModuleFunc(func(ctx context.Context, module api.Module, stack []uint64) { message := HostInformation positionReturnBuffer := uint32(stack[0]) lengthReturnBuffer := uint32(stack[1]) memory.WriteStringToMemory(message, ctx, module, positionReturnBuffer, lengthReturnBuffer) stack[0] = 0 })
GetHostInformation returns information about the host
var HostInformation = ""
HostInformation updated in `services/http/http.go`
var Http = api.GoModuleFunc(func(ctx context.Context, module api.Module, stack []uint64) { positionUrl := uint32(stack[0]) lengthUrl := uint32(stack[1]) urlStr := memory.ReadStringFromMemory(ctx, module, positionUrl, lengthUrl) positionMethod := uint32(stack[2]) lengthMethod := uint32(stack[3]) methodStr := memory.ReadStringFromMemory(ctx, module, positionMethod, lengthMethod) positionHeaders := uint32(stack[4]) lengthHeaders := uint32(stack[5]) headersStr := memory.ReadStringFromMemory(ctx, module, positionHeaders, lengthHeaders) headersSlice := commons.CreateSliceFromString(headersStr, commons.StrSeparator) headersMap := commons.CreateMapFromSlice(headersSlice, commons.FieldSeparator) positionBody := uint32(stack[6]) lengthBody := uint32(stack[7]) bodyStr := memory.ReadStringFromMemory(ctx, module, positionBody, lengthBody) var stringResultFromHost = "" client := resty.New() for key, value := range headersMap { client.SetHeader(key, value) } switch what := methodStr; what { case "GET": resp, err := client.R().EnableTrace().Get(urlStr) if err != nil { stringResultFromHost = commons.CreateStringError(err.Error(), 0) } else { stringResultFromHost = resp.String() } case "POST": resp, err := client.R().EnableTrace().SetBody(bodyStr).Post(urlStr) if err != nil { stringResultFromHost = commons.CreateStringError(err.Error(), 0) } else { stringResultFromHost = resp.String() } default: stringResultFromHost = commons.CreateStringError("🔴"+methodStr+" is not yet implemented: 🚧 wip", 0) } positionReturnBuffer := uint32(stack[8]) lengthReturnBuffer := uint32(stack[9]) memory.WriteStringToMemory(stringResultFromHost, ctx, module, positionReturnBuffer, lengthReturnBuffer) stack[0] = 0 })
var LogString = api.GoModuleFunc(func(ctx context.Context, module api.Module, stack []uint64) { position := uint32(stack[0]) length := uint32(stack[1]) buffer, ok := module.Memory().Read(position, length) if !ok { log.Panicf("🟥 Memory.Read(%d, %d) out of range", position, length) } fmt.Println(string(buffer)) stack[0] = 0 })
LogString : print a string to the console
var MemoryGet = api.GoModuleFunc(func(ctx context.Context, module api.Module, stack []uint64) { keyPosition := uint32(stack[0]) keyLength := uint32(stack[1]) keyStr := memory.ReadStringFromMemory(ctx, module, keyPosition, keyLength) valueStr := memoryMap[keyStr] var stringResultFromHost = "" if len(valueStr) == 0 { stringResultFromHost = commons.CreateStringError("key does not exist", 0) } else { stringResultFromHost = valueStr } positionReturnBuffer := uint32(stack[2]) lengthReturnBuffer := uint32(stack[3]) memory.WriteStringToMemory(stringResultFromHost, ctx, module, positionReturnBuffer, lengthReturnBuffer) stack[0] = 0 })
var MemoryKeys = api.GoModuleFunc(func(ctx context.Context, module api.Module, stack []uint64) { var keys []string for key, _ := range memoryMap { keys = append(keys, key) } stringResultFromHost := commons.CreateStringFromSlice(keys, commons.StrSeparator) positionReturnBuffer := uint32(stack[0]) lengthReturnBuffer := uint32(stack[1]) memory.WriteStringToMemory(stringResultFromHost, ctx, module, positionReturnBuffer, lengthReturnBuffer) stack[0] = 0 })
var MemorySet = api.GoModuleFunc(func(ctx context.Context, module api.Module, stack []uint64) { keyPosition := uint32(stack[0]) keyLength := uint32(stack[1]) keyStr := memory.ReadStringFromMemory(ctx, module, keyPosition, keyLength) valuePosition := uint32(stack[2]) valueLength := uint32(stack[3]) valueStr := memory.ReadStringFromMemory(ctx, module, valuePosition, valueLength) memoryMap[keyStr] = valueStr stringResultFromHost := "[OK](" + keyStr + ":" + valueStr + ")" positionReturnBuffer := uint32(stack[4]) lengthReturnBuffer := uint32(stack[5]) memory.WriteStringToMemory(stringResultFromHost, ctx, module, positionReturnBuffer, lengthReturnBuffer) stack[0] = 0 })
var MqttConnectPublish = api.GoModuleFunc(func(ctx context.Context, module api.Module, stack []uint64) { var stringResultFromHost = "" mqttSrvOffset := uint32(stack[0]) mqttSrvByteCount := uint32(stack[1]) mqttSrv := memory.ReadStringFromMemory(ctx, module, mqttSrvOffset, mqttSrvByteCount) clientIdPtrOffset := uint32(stack[2]) clientIdByteCount := uint32(stack[3]) mqttClientId := memory.ReadStringFromMemory(ctx, module, clientIdPtrOffset, clientIdByteCount) opts := mqtt.NewClientOptions() opts.AddBroker(fmt.Sprintf("tcp://%s", mqttSrv)) opts.SetClientID(mqttClientId) mqttClient := mqtt.NewClient(opts) token := mqttClient.Connect() token.Wait() errConn := token.Error() defer mqttClient.Disconnect(250) if errConn != nil { fmt.Println("1️⃣😡", errConn.Error()) stringResultFromHost = commons.CreateStringError(errConn.Error(), 0) } else { topicOffset := uint32(stack[4]) topicByteCount := uint32(stack[5]) topic := memory.ReadStringFromMemory(ctx, module, topicOffset, topicByteCount) dataOffset := uint32(stack[6]) dataByteCount := uint32(stack[7]) data := memory.ReadStringFromMemory(ctx, module, dataOffset, dataByteCount) token := mqttClient.Publish(topic, 0, false, data) token.Wait() errPub := token.Error() if errPub != nil { stringResultFromHost = commons.CreateStringError(errPub.Error(), 0) } else { stringResultFromHost = "[OK](" + topic + ":" + data + ")" } } retBuffPtrPos := uint32(stack[8]) retBuffSize := uint32(stack[9]) memory.WriteStringToMemory(stringResultFromHost, ctx, module, retBuffPtrPos, retBuffSize) stack[0] = 0 })
MqttConnectPublish : only if context is cli or http
var MqttGetClientId = api.GoModuleFunc(func(ctx context.Context, module api.Module, stack []uint64) { server := mqttconn.GetCapsuleMqttClientId() retBuffPtrPos := uint32(stack[0]) retBuffSize := uint32(stack[1]) memory.WriteStringToMemory(server, ctx, module, retBuffPtrPos, retBuffSize) stack[0] = 0 })
var MqttGetServer = api.GoModuleFunc(func(ctx context.Context, module api.Module, stack []uint64) { server := mqttconn.GetCapsuleMqttServer() retBuffPtrPos := uint32(stack[0]) retBuffSize := uint32(stack[1]) memory.WriteStringToMemory(server, ctx, module, retBuffPtrPos, retBuffSize) stack[0] = 0 })
var MqttGetTopic = api.GoModuleFunc(func(ctx context.Context, module api.Module, stack []uint64) { topic := mqttconn.GetCapsuleMqttTopic() retBuffPtrPos := uint32(stack[0]) retBuffSize := uint32(stack[1]) memory.WriteStringToMemory(topic, ctx, module, retBuffPtrPos, retBuffSize) stack[0] = 0 })
MqttGetTopic return the MQTT Topic of the capsule launcher
var MqttPublish = api.GoModuleFunc(func(ctx context.Context, module api.Module, stack []uint64) { mqttClient, errConn := mqttconn.GetCapsuleMqttConn() var stringResultFromHost = "" if errConn != nil { stringResultFromHost = commons.CreateStringError(errConn.Error(), 0) } else { topicOffset := uint32(stack[0]) topicByteCount := uint32(stack[1]) topic := memory.ReadStringFromMemory(ctx, module, topicOffset, topicByteCount) dataOffset := uint32(stack[2]) dataByteCount := uint32(stack[3]) data := memory.ReadStringFromMemory(ctx, module, dataOffset, dataByteCount) token := mqttClient.Publish(topic, 0, false, data) token.Wait() errPub := token.Error() if errPub != nil { stringResultFromHost = commons.CreateStringError(errPub.Error(), 0) } else { stringResultFromHost = "[OK](" + topic + ":" + data + ")" } } retBuffPtrPos := uint32(stack[4]) retBuffSize := uint32(stack[5]) memory.WriteStringToMemory(stringResultFromHost, ctx, module, retBuffPtrPos, retBuffSize) stack[0] = 0 })
MqttPublish : only if context is mqtt
var NatsConnectPublish = api.GoModuleFunc(func(ctx context.Context, module api.Module, stack []uint64) { var stringResultFromHost = "" natsSrvOffset := uint32(stack[0]) natsSrvByteCount := uint32(stack[1]) natsSrv := memory.ReadStringFromMemory(ctx, module, natsSrvOffset, natsSrvByteCount) natscn, errConn := nats.Connect(natsSrv) defer natscn.Close() if errConn != nil { stringResultFromHost = commons.CreateStringError(errConn.Error(), 0) } else { subjectOffset := uint32(stack[2]) subjectByteCount := uint32(stack[3]) subject := memory.ReadStringFromMemory(ctx, module, subjectOffset, subjectByteCount) dataOffset := uint32(stack[4]) dataByteCount := uint32(stack[5]) data := memory.ReadStringFromMemory(ctx, module, dataOffset, dataByteCount) errPub := natscn.Publish(subject, []byte(data)) if errPub != nil { stringResultFromHost = commons.CreateStringError(errPub.Error(), 0) } else { stringResultFromHost = "[OK](" + subject + ":" + data + ")" } } retBuffPtrPos := uint32(stack[6]) retBuffSize := uint32(stack[7]) memory.WriteStringToMemory(stringResultFromHost, ctx, module, retBuffPtrPos, retBuffSize) stack[0] = 0 })
NatsConnectPublish : only if context is cli or http
var NatsConnectRequest = api.GoModuleFunc(func(ctx context.Context, module api.Module, stack []uint64) { var stringResultFromHost = "" natsSrvOffset := uint32(stack[0]) natsSrvByteCount := uint32(stack[1]) natsSrv := memory.ReadStringFromMemory(ctx, module, natsSrvOffset, natsSrvByteCount) natscn, errConn := nats.Connect(natsSrv) defer natscn.Close() if errConn != nil { stringResultFromHost = commons.CreateStringError(errConn.Error(), 0) } else { subjectOffset := uint32(stack[2]) subjectByteCount := uint32(stack[3]) subject := memory.ReadStringFromMemory(ctx, module, subjectOffset, subjectByteCount) dataOffset := uint32(stack[4]) dataByteCount := uint32(stack[5]) data := memory.ReadStringFromMemory(ctx, module, dataOffset, dataByteCount) timeoutSecondDuration := uint32(stack[6]) replyMsg, errPub := natscn.Request(subject, []byte(data), time.Duration(timeoutSecondDuration)*time.Second) if errPub != nil { stringResultFromHost = commons.CreateStringError(errPub.Error(), 0) } else { stringResultFromHost = string(replyMsg.Data) } } retBuffPtrPos := uint32(stack[7]) retBuffSize := uint32(stack[8]) memory.WriteStringToMemory(stringResultFromHost, ctx, module, retBuffPtrPos, retBuffSize) stack[0] = 0 })
NatsConnectRequest : only if context is cli or http (???) ref: https://docs.nats.io/using-nats/developer/sending/request_reply
var NatsGetServer = api.GoModuleFunc(func(ctx context.Context, module api.Module, stack []uint64) { server := natsconn.GetCapsuleNatsServer() retBuffPtrPos := uint32(stack[0]) retBuffSize := uint32(stack[1]) memory.WriteStringToMemory(server, ctx, module, retBuffPtrPos, retBuffSize) stack[0] = 0 })
var NatsGetSubject = api.GoModuleFunc(func(ctx context.Context, module api.Module, stack []uint64) { subject := natsconn.GetCapsuleNatsSubject() retBuffPtrPos := uint32(stack[0]) retBuffSize := uint32(stack[1]) memory.WriteStringToMemory(subject, ctx, module, retBuffPtrPos, retBuffSize) stack[0] = 0 })
NatsGetSubject return the NATS subject of the capsule launcher
var NatsPublish = api.GoModuleFunc(func(ctx context.Context, module api.Module, stack []uint64) { nc, errConn := natsconn.GetCapsuleNatsConn() var stringResultFromHost = "" if errConn != nil { stringResultFromHost = commons.CreateStringError(errConn.Error(), 0) } else { subjectOffset := uint32(stack[0]) subjectByteCount := uint32(stack[1]) subject := memory.ReadStringFromMemory(ctx, module, subjectOffset, subjectByteCount) dataOffset := uint32(stack[2]) dataByteCount := uint32(stack[3]) data := memory.ReadStringFromMemory(ctx, module, dataOffset, dataByteCount) errPub := nc.Publish(subject, []byte(data)) if errPub != nil { stringResultFromHost = commons.CreateStringError(errPub.Error(), 0) } else { stringResultFromHost = "[OK](" + subject + ":" + data + ")" } } retBuffPtrPos := uint32(stack[4]) retBuffSize := uint32(stack[5]) memory.WriteStringToMemory(stringResultFromHost, ctx, module, retBuffPtrPos, retBuffSize) stack[0] = 0 })
NatsPublish : only if context is nats (the module is a subscriber) func NatsPublish(ctx context.Context, module api.Module, subjectOffset, subjectByteCount, dataOffset, dataByteCount, retBuffPtrPos, retBuffSize uint32) {
var NatsReply = api.GoModuleFunc(func(ctx context.Context, module api.Module, stack []uint64) { sub, errSub := natsconn.GetCapsuleNatsSubscription() var stringResultFromHost = "" if errSub != nil { stringResultFromHost = commons.CreateStringError(errSub.Error(), 0) } else { dataOffset := uint32(stack[0]) dataByteCount := uint32(stack[1]) data := memory.ReadStringFromMemory(ctx, module, dataOffset, dataByteCount) timeoutSecondDuration := uint32(stack[2]) msg, errMsg := sub.NextMsg(time.Duration(timeoutSecondDuration) * time.Second) if errMsg != nil { stringResultFromHost = commons.CreateStringError(errMsg.Error(), 0) } else { errResp := msg.Respond([]byte(data)) if errResp != nil { stringResultFromHost = commons.CreateStringError(errResp.Error(), 0) } else { stringResultFromHost = "[OK](" + natsconn.GetCapsuleNatsSubject() + ":" + data + ")" } } } retBuffPtrPos := uint32(stack[3]) retBuffSize := uint32(stack[4]) memory.WriteStringToMemory(stringResultFromHost, ctx, module, retBuffPtrPos, retBuffSize) stack[0] = 0 })
NatsReply : only if context is nats (the module is a subscriber)
var ReadFile = api.GoModuleFunc(func(ctx context.Context, module api.Module, stack []uint64) { positionFilePathName := uint32(stack[0]) lengthFilePathName := uint32(stack[1]) filePath := memory.ReadStringFromMemory(ctx, module, positionFilePathName, lengthFilePathName) var stringResultFromHost = "" data, err := os.ReadFile(filePath) if err != nil { stringResultFromHost = commons.CreateStringError(err.Error(), 0) } else { stringResultFromHost = string(data) } positionReturnBuffer := uint32(stack[2]) lengthReturnBuffer := uint32(stack[3]) memory.WriteStringToMemory(stringResultFromHost, ctx, module, positionReturnBuffer, lengthReturnBuffer) stack[0] = 0 })
ReadFile : string parameter, return string
var RedisGet = api.GoModuleFunc(func(ctx context.Context, module api.Module, stack []uint64) { InitRedisCli() keyPosition := uint32(stack[0]) keyLength := uint32(stack[1]) keyStr := memory.ReadStringFromMemory(ctx, module, keyPosition, keyLength) valueStr, err := getRedisCli().Get(ctx, keyStr).Result() var stringResultFromHost = "" if err != nil { stringResultFromHost = commons.CreateStringError(err.Error(), 0) } else { stringResultFromHost = valueStr } positionReturnBuffer := uint32(stack[2]) lengthReturnBuffer := uint32(stack[3]) memory.WriteStringToMemory(stringResultFromHost, ctx, module, positionReturnBuffer, lengthReturnBuffer) stack[0] = 0 })
RedisGet : The wasm module will call this function like this: `func RedisGet(key string) (string, error)`
var RedisKeys = api.GoModuleFunc(func(ctx context.Context, module api.Module, stack []uint64) { InitRedisCli() patternPosition := uint32(stack[0]) patternLength := uint32(stack[1]) patternStr := memory.ReadStringFromMemory(ctx, module, patternPosition, patternLength) valueStr, err := getRedisCli().Keys(ctx, patternStr).Result() var stringResultFromHost = "" if err != nil { stringResultFromHost = commons.CreateStringError(err.Error(), 0) } else { stringResultFromHost = commons.CreateStringFromSlice(valueStr, commons.StrSeparator) } positionReturnBuffer := uint32(stack[2]) lengthReturnBuffer := uint32(stack[3]) memory.WriteStringToMemory(stringResultFromHost, ctx, module, positionReturnBuffer, lengthReturnBuffer) stack[0] = 0 })
RedisKeys : get all the keys (with a pattern) The wasm module will call this function like this: `func RedisKeys(pattern string) (string, error)`
var RedisSet = api.GoModuleFunc(func(ctx context.Context, module api.Module, stack []uint64) { InitRedisCli() keyPosition := uint32(stack[0]) keyLength := uint32(stack[1]) keyStr := memory.ReadStringFromMemory(ctx, module, keyPosition, keyLength) valuePosition := uint32(stack[2]) valueLength := uint32(stack[3]) valueStr := memory.ReadStringFromMemory(ctx, module, valuePosition, valueLength) err := getRedisCli().Set(ctx, keyStr, valueStr, 0).Err() var stringResultFromHost = "" if err != nil { stringResultFromHost = commons.CreateStringError(err.Error(), 0) } else { stringResultFromHost = "[OK](" + keyStr + ":" + valueStr + ")" } positionReturnBuffer := uint32(stack[4]) lengthReturnBuffer := uint32(stack[5]) memory.WriteStringToMemory(stringResultFromHost, ctx, module, positionReturnBuffer, lengthReturnBuffer) stack[0] = 0 })
RedisSet : The wasm module will call this function like this: `func RedisSet(key string, value) (string, error)`
var RequestParamsGet = api.GoModuleFunc(func(ctx context.Context, module api.Module, stack []uint64) { reqId := uint32(stack[0]) reqParams, err := GetRequestParams(reqId) // This variable will store the concatenation of reqParams.JsonData, reqParams.Headers, reqParams.Uri, reqParams.Method var stringResultFromHost = "" if err != nil { stringResultFromHost = commons.CreateStringError("key (requestId) does not exist", 0) } else { stringResultFromHost = commons.CreateStringFromSlice([]string{reqParams.JsonData, reqParams.Headers, reqParams.Uri, reqParams.Method}, commons.StrSeparator) } positionReturnBuffer := uint32(stack[1]) lengthReturnBuffer := uint32(stack[2]) memory.WriteStringToMemory(stringResultFromHost, ctx, module, positionReturnBuffer, lengthReturnBuffer) stack[0] = 0 })
var WriteFile = api.GoModuleFunc(func(ctx context.Context, module api.Module, stack []uint64) { positionFilePathName := uint32(stack[0]) lengthFilePathName := uint32(stack[1]) filePath := memory.ReadStringFromMemory(ctx, module, positionFilePathName, lengthFilePathName) positionContent := uint32(stack[2]) lengthContent := uint32(stack[3]) content := memory.ReadStringFromMemory(ctx, module, positionContent, lengthContent) var stringResultFromHost = "" data := []byte(content) err := os.WriteFile(filePath, data, 0644) if err != nil { stringResultFromHost = commons.CreateStringError(err.Error(), 0) } else { stringResultFromHost = "file created" } positionReturnBuffer := uint32(stack[4]) lengthReturnBuffer := uint32(stack[5]) memory.WriteStringToMemory(stringResultFromHost, ctx, module, positionReturnBuffer, lengthReturnBuffer) stack[0] = 0 })
Functions ¶
func DeleteRequestParams ¶
func DeleteRequestParams(reqId uint32)
func DeleteRequestParams(reqId string) {
func FunctionName ¶
func FunctionName(ctx context.Context, module api.Module, paramOffset, paramByteCount, retBuffPtrPos, retBuffSize uint32)
FunctionName : The wasm module will call this function like this: `func FunctionName(param string) (string, error)`
func GetHeadersStringFromHeadersRequest ¶
func GetHeadersStringFromHeadersRequest(c *fiber.Ctx) string
GetHeadersStringFromHeadersRequest :
func InitCouchBaseCluster ¶
func InitCouchBaseCluster()
func InitRedisCli ¶
func InitRedisCli()
func StoreRequestParams ¶
func StoreRequestParams(c *fiber.Ctx) uint32
StoreRequestParams stores json data + headers + uri + method and returns the requestId
Types ¶
type WasmRequestParam ¶
func GetRequestParams ¶
func GetRequestParams(reqId uint32) (WasmRequestParam, error)
func GetRequestParams(reqId string) (WasmRequestParam, error) {