sdk

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package sdk is a client package for WASM functions running within a Tarmac server.

This package provides user-friendly functions that wrap the Web Assembly Procedure Call (waPC) based functions of Tarmac. Guest WASM functions running inside Tarmac can use this library to call back the Tarmac host and perform host-level actions such as storing data within the database, logging specific data, or looking up configurations.

import "github.com/madflojo/tarmac/pkg/sdk"

var tarmac *Tarmac

func main() {
	tarmac, err := sdk.New(sdk.Config{Namespace: "my-service", Handler: Handler})
	if err != nil {
		// do something
	}
}

func Handler(payload []byte) ([]byte, error) {
	tarmac.Logger.Info("This is a log message")
	return []byte("Hello World"), nil
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Namespace controls the function namespace to use for host callbacks. The default value is "default" which is the global namespace.
	// Users can provide an alternative namespace by specifying this field.
	Namespace string

	// Handler registers the user function to execute as part of the Tarmac Function.
	Handler func([]byte) ([]byte, error)
	// contains filtered or unexported fields
}

Config provides users with the ability to specify namespaces, function handlers and other key information required to execute the function.

type Tarmac

type Tarmac struct {

	// HTTP provides an interface to the Tarmac HTTP client, enabling users to make HTTP requests from functions.
	HTTP *http.Client

	// KV provides an interface to the Tarmac KVStore, enabling users to store and retrieve key-value pairs from functions.
	KV *kvstore.KV

	// SQL provides an interface to the underlying SQL datastores within Tarmac.
	SQL *sql.SQL

	// Function provides an interface to call other WASM functions registered within Tarmac.
	Function *function.Function

	// Logger provides an interface to the Tarmac structured logger, enabling users to create log messages from functions.
	Logger *logger.Logger

	// Metrics provides an interface to Tarmac metrics, enabling users to create custom metrics from functions.
	Metrics *metrics.Metrics
	// contains filtered or unexported fields
}

Tarmac provides an interface to users which wraps and simplifies the interfaces for WASM Functions execute by Tarmac. This interface provides access to Loggers, Metrics, KVs, and SQL Databases.

func New

func New(cfg Config) (*Tarmac, error)

New creates a new Tarmac instance with the specified configuration.

Directories

Path Synopsis
Package function is a client package for WASM functions running within a Tarmac server.
Package function is a client package for WASM functions running within a Tarmac server.
Package http is a client package for WASM functions running within a Tarmac server.
Package http is a client package for WASM functions running within a Tarmac server.
Package kvstore is a client package for WASM functions running within a Tarmac server.
Package kvstore is a client package for WASM functions running within a Tarmac server.
Package logger is a client package for WASM functions running within a Tarmac server.
Package logger is a client package for WASM functions running within a Tarmac server.
Package metrics is a client package for WASM functions running within a Tarmac server.
Package metrics is a client package for WASM functions running within a Tarmac server.
Package sql is a client package for WASM functions running within a Tarmac server.
Package sql is a client package for WASM functions running within a Tarmac server.

Jump to

Keyboard shortcuts

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