actor

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2023 License: Apache-2.0 Imports: 5 Imported by: 14

README

wasmCloud TinyGo Actor SDK

This module is for those looking to develop wasmCloud actors using TinyGo. Typically you won't use this module directly, as it will be referenced by one or more code generate modules containing strongly-typed structs and wrappers around function handler registration.

A typical actor might look like this

package main

import (
	"github.com/wasmcloud/actor-tinygo"
	"github.com/wasmcloud/interfaces/httpserver/tinygo"
)

func main() {
	// In the main function, construct an instance of your actor, and pass in the instance,
	// followed by a handler for each of the interfaces you implement.
	// This actor responsds to http requests from the http server capability provider,
	// so it includes the HttpServerHandler.
	// All actors must include the ActorHandler and implement `HealthRequest`.
	me := Echo{}
	actor.RegisterHandlers(httpserver.HttpServerHandler(&me), actor.ActorHandler(&me))
}

type Echo struct{}

// HandleRequest implements the callback from the http server capability provider.
func (e *Echo) HandleRequest(ctx *actor.Context, arg httpserver.HttpRequest) (*httpserver.HttpResponse, error) {
	r := httpserver.HttpResponse{
		StatusCode: 200,
		Header:     make(httpserver.HeaderMap, 0),
		Body:       []byte("hello"),
	}
	return &r, nil
}

// HealthRequest implements the health check from the wasmcloud host.
func (e *Echo) HealthRequest(ctx *actor.Context, arg actor.HealthCheckRequest) (*actor.HealthCheckResponse, error) {
	var r actor.HealthCheckResponse
	r.Healthy = true
	return &r, nil
}

Documentation

Overview

wasmcloud platform core data structures

wasmcloud core data models for messaging and code generation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConsoleLog

func ConsoleLog(msg string)

ConsoleLog sends log message to host console. For internal use - Actors should use the logging capability provider for logging Deprecated - support for this function may go away

func HostCall

func HostCall(binding, namespace, operation string, payload []byte) ([]byte, error)

HostCall performs a "host call" - a request from the actor to either invoke another actor or invoke an operation on a linked capability provider.

binding - this is either the link name (e.g. "default") or, in the case of an actor-to-actor call, the public key or call alias of the target

namespace - this is the contract ID when invoking a provider, empty string for actor-to-actor calls

operation - the name of the operation to invoke

func RegisterHandlers

func RegisterHandlers(handlers ...Handler)

RegisterHandlers is called by actors during main() Example: ``` me = MyActor{} actor.RegisterHandlers(me, actor.Handler(), httpserver.Handler()) ```

Types

type Actor

type Actor interface {
	// Perform health check. Called at regular intervals by host
	HealthRequest(ctx *Context, arg HealthCheckRequest) (*HealthCheckResponse, error)
}

Actor service

type ActorLinks []LinkDefinition

List of linked actors for a provider

func CDecodeActorLinks(d *cbor.Decoder) (ActorLinks, error)

CDecodeActorLinks deserializes a ActorLinks using cbor

func MDecodeActorLinks(d *msgpack.Decoder) (ActorLinks, error)

MDecodeActorLinks deserializes a ActorLinks using msgpack

func (*ActorLinks) CEncode added in v0.1.2

func (o *ActorLinks) CEncode(encoder cbor.Writer) error

CEncode serializes a ActorLinks using cbor

func (*ActorLinks) MEncode added in v0.1.2

func (o *ActorLinks) MEncode(encoder msgpack.Writer) error

MEncode serializes a ActorLinks using msgpack

type ActorReceiver

type ActorReceiver struct{}

ActorReceiver receives messages defined in the Actor service interface Actor service

func (*ActorReceiver) Dispatch

func (r *ActorReceiver) Dispatch(ctx *Context, svc interface{}, message *Message) (*Message, error)

type ActorSender

type ActorSender struct {
	// contains filtered or unexported fields
}

ActorSender sends messages to a Actor service Actor service

func NewActorActorSender

func NewActorActorSender(actor_id string) *ActorSender

NewActorSender constructs a client for actor-to-actor messaging using the recipient actor's public key

func (*ActorSender) HealthRequest

func (s *ActorSender) HealthRequest(ctx *Context, arg HealthCheckRequest) (*HealthCheckResponse, error)

Perform health check. Called at regular intervals by host

type CapabilityContractId

type CapabilityContractId string

Capability contract id, e.g. 'wasmcloud:httpserver' This declaration supports code generations and is not part of an actor or provider sdk

func CDecodeCapabilityContractId added in v0.1.2

func CDecodeCapabilityContractId(d *cbor.Decoder) (CapabilityContractId, error)

CDecodeCapabilityContractId deserializes a CapabilityContractId using cbor

func MDecodeCapabilityContractId added in v0.1.2

func MDecodeCapabilityContractId(d *msgpack.Decoder) (CapabilityContractId, error)

MDecodeCapabilityContractId deserializes a CapabilityContractId using msgpack

func (*CapabilityContractId) CEncode added in v0.1.2

func (o *CapabilityContractId) CEncode(encoder cbor.Writer) error

CEncode serializes a CapabilityContractId using cbor

func (*CapabilityContractId) MEncode added in v0.1.2

func (o *CapabilityContractId) MEncode(encoder msgpack.Writer) error

MEncode serializes a CapabilityContractId using msgpack

type ClusterIssuerKey

type ClusterIssuerKey string

func CDecodeClusterIssuerKey added in v0.1.2

func CDecodeClusterIssuerKey(d *cbor.Decoder) (ClusterIssuerKey, error)

CDecodeClusterIssuerKey deserializes a ClusterIssuerKey using cbor

func MDecodeClusterIssuerKey added in v0.1.2

func MDecodeClusterIssuerKey(d *msgpack.Decoder) (ClusterIssuerKey, error)

MDecodeClusterIssuerKey deserializes a ClusterIssuerKey using msgpack

func (*ClusterIssuerKey) CEncode added in v0.1.2

func (o *ClusterIssuerKey) CEncode(encoder cbor.Writer) error

CEncode serializes a ClusterIssuerKey using cbor

func (*ClusterIssuerKey) MEncode added in v0.1.2

func (o *ClusterIssuerKey) MEncode(encoder msgpack.Writer) error

MEncode serializes a ClusterIssuerKey using msgpack

type ClusterIssuers

type ClusterIssuers []ClusterIssuerKey

func CDecodeClusterIssuers added in v0.1.2

func CDecodeClusterIssuers(d *cbor.Decoder) (ClusterIssuers, error)

CDecodeClusterIssuers deserializes a ClusterIssuers using cbor

func MDecodeClusterIssuers added in v0.1.2

func MDecodeClusterIssuers(d *msgpack.Decoder) (ClusterIssuers, error)

MDecodeClusterIssuers deserializes a ClusterIssuers using msgpack

func (*ClusterIssuers) CEncode added in v0.1.2

func (o *ClusterIssuers) CEncode(encoder cbor.Writer) error

CEncode serializes a ClusterIssuers using cbor

func (*ClusterIssuers) MEncode added in v0.1.2

func (o *ClusterIssuers) MEncode(encoder msgpack.Writer) error

MEncode serializes a ClusterIssuers using msgpack

type Context

type Context struct{}

Context object passed through rpc methods

type DefaultResponder added in v0.1.2

type DefaultResponder struct{}

default health check responder

func (*DefaultResponder) HealthRequest added in v0.1.2

func (hc *DefaultResponder) HealthRequest(ctx *Context, arg HealthCheckRequest) (*HealthCheckResponse, error)

type Document

type Document struct{}

Document is an 'any' type interface and is not currently implemented for TinyGo actors

func CDecodeDocument added in v0.1.2

func CDecodeDocument(d *cbor.Decoder) Document

func MDecodeDocument added in v0.1.2

func MDecodeDocument(d *msgpack.Decoder) Document

func (*Document) CEncode added in v0.1.2

func (o *Document) CEncode(encoder cbor.Writer) error

func (*Document) MEncode added in v0.1.2

func (o *Document) MEncode(encoder msgpack.Writer) error

type F32

type F32 float32

32-bit float

type F64

type F64 float64

64-bit float aka double

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler used to invoke callbacks when actor receives a message

func ActorHandler

func ActorHandler(actor_ Actor) Handler

ActorHandler is called by an actor during `main` to generate a dispatch handler The output of this call should be passed into `actor.RegisterHandlers`

func NewHandler

func NewHandler(service string, dispatch ServiceDispatch, actor interface{}) Handler

NewHandler constructor - called by service (generated interface) during actor initialization Not used directly by actors. Actors should use RegisterHandlers

type HealthCheckRequest

type HealthCheckRequest struct {
}

health check request parameter

func CDecodeHealthCheckRequest added in v0.1.2

func CDecodeHealthCheckRequest(d *cbor.Decoder) (HealthCheckRequest, error)

CDecodeHealthCheckRequest deserializes a HealthCheckRequest using cbor

func MDecodeHealthCheckRequest added in v0.1.2

func MDecodeHealthCheckRequest(d *msgpack.Decoder) (HealthCheckRequest, error)

MDecodeHealthCheckRequest deserializes a HealthCheckRequest using msgpack

func (*HealthCheckRequest) CEncode added in v0.1.2

func (o *HealthCheckRequest) CEncode(encoder cbor.Writer) error

CEncode serializes a HealthCheckRequest using cbor

func (*HealthCheckRequest) MEncode added in v0.1.2

func (o *HealthCheckRequest) MEncode(encoder msgpack.Writer) error

MEncode serializes a HealthCheckRequest using msgpack

type HealthCheckResponse

type HealthCheckResponse struct {
	// A flag that indicates the the actor is healthy
	Healthy bool
	// A message containing additional information about the actors health
	Message string
}

Return value from actors and providers for health check status

func CDecodeHealthCheckResponse added in v0.1.2

func CDecodeHealthCheckResponse(d *cbor.Decoder) (HealthCheckResponse, error)

CDecodeHealthCheckResponse deserializes a HealthCheckResponse using cbor

func MDecodeHealthCheckResponse added in v0.1.2

func MDecodeHealthCheckResponse(d *msgpack.Decoder) (HealthCheckResponse, error)

MDecodeHealthCheckResponse deserializes a HealthCheckResponse using msgpack

func (*HealthCheckResponse) CEncode added in v0.1.2

func (o *HealthCheckResponse) CEncode(encoder cbor.Writer) error

CEncode serializes a HealthCheckResponse using cbor

func (*HealthCheckResponse) MEncode added in v0.1.2

func (o *HealthCheckResponse) MEncode(encoder msgpack.Writer) error

MEncode serializes a HealthCheckResponse using msgpack

type HostData

type HostData struct {
	HostId             string
	LatticeRpcPrefix   string
	LinkName           string
	LatticeRpcUserJwt  string
	LatticeRpcUserSeed string
	LatticeRpcUrl      string
	ProviderKey        string
	InvocationSeed     string
	EnvValues          HostEnvValues
	InstanceId         string
	// initial list of links for provider
	LinkDefinitions ActorLinks
	// list of cluster issuers
	ClusterIssuers ClusterIssuers
	// Optional configuration JSON sent to a given link name of a provider
	// without an actor context
	ConfigJson string
	// Host-wide default RPC timeout for rpc messages, in milliseconds.  Defaults to 2000.
	DefaultRpcTimeoutMs uint64
}

initialization data for a capability provider

func CDecodeHostData added in v0.1.2

func CDecodeHostData(d *cbor.Decoder) (HostData, error)

CDecodeHostData deserializes a HostData using cbor

func MDecodeHostData added in v0.1.2

func MDecodeHostData(d *msgpack.Decoder) (HostData, error)

MDecodeHostData deserializes a HostData using msgpack

func (*HostData) CEncode added in v0.1.2

func (o *HostData) CEncode(encoder cbor.Writer) error

CEncode serializes a HostData using cbor

func (*HostData) MEncode added in v0.1.2

func (o *HostData) MEncode(encoder msgpack.Writer) error

MEncode serializes a HostData using msgpack

type HostEnvValues

type HostEnvValues map[string]string

Environment settings for initializing a capability provider

func CDecodeHostEnvValues added in v0.1.2

func CDecodeHostEnvValues(d *cbor.Decoder) (HostEnvValues, error)

CDecodeHostEnvValues deserializes a HostEnvValues using cbor

func MDecodeHostEnvValues added in v0.1.2

func MDecodeHostEnvValues(d *msgpack.Decoder) (HostEnvValues, error)

MDecodeHostEnvValues deserializes a HostEnvValues using msgpack

func (*HostEnvValues) CEncode added in v0.1.2

func (o *HostEnvValues) CEncode(encoder cbor.Writer) error

CEncode serializes a HostEnvValues using cbor

func (*HostEnvValues) MEncode added in v0.1.2

func (o *HostEnvValues) MEncode(encoder msgpack.Writer) error

MEncode serializes a HostEnvValues using msgpack

type HostError

type HostError struct {
	// contains filtered or unexported fields
}

HostError is returned by the host from HostCall

func (*HostError) Error

func (e *HostError) Error() string

Error implements the error interface for HostError

type I16

type I16 int16

signed 16-bit int

type I32

type I32 int32

signed 32-bit int

type I64

type I64 int64

signed 64-bit int

type I8

type I8 int8

signed byte

type IdentifierList

type IdentifierList []string

list of identifiers This declaration supports code generations and is not part of an actor or provider sdk

func CDecodeIdentifierList added in v0.1.2

func CDecodeIdentifierList(d *cbor.Decoder) (IdentifierList, error)

CDecodeIdentifierList deserializes a IdentifierList using cbor

func MDecodeIdentifierList added in v0.1.2

func MDecodeIdentifierList(d *msgpack.Decoder) (IdentifierList, error)

MDecodeIdentifierList deserializes a IdentifierList using msgpack

func (*IdentifierList) CEncode added in v0.1.2

func (o *IdentifierList) CEncode(encoder cbor.Writer) error

CEncode serializes a IdentifierList using cbor

func (*IdentifierList) MEncode added in v0.1.2

func (o *IdentifierList) MEncode(encoder msgpack.Writer) error

MEncode serializes a IdentifierList using msgpack

type Invocation

type Invocation struct {
	Origin        WasmCloudEntity
	Target        WasmCloudEntity
	Operation     string
	Msg           []byte
	Id            string
	EncodedClaims string
	HostId        string
	// total message size (optional)
	ContentLength uint64
	// Open Telemetry tracing support
	TraceContext TraceContext
}

RPC message to capability provider

func CDecodeInvocation added in v0.1.2

func CDecodeInvocation(d *cbor.Decoder) (Invocation, error)

CDecodeInvocation deserializes a Invocation using cbor

func MDecodeInvocation added in v0.1.2

func MDecodeInvocation(d *msgpack.Decoder) (Invocation, error)

MDecodeInvocation deserializes a Invocation using msgpack

func (*Invocation) CEncode added in v0.1.2

func (o *Invocation) CEncode(encoder cbor.Writer) error

CEncode serializes a Invocation using cbor

func (*Invocation) MEncode added in v0.1.2

func (o *Invocation) MEncode(encoder msgpack.Writer) error

MEncode serializes a Invocation using msgpack

type InvocationResponse

type InvocationResponse struct {
	// serialize response message
	Msg []byte
	// id connecting this response to the invocation
	InvocationId string
	// optional error message
	Error string
	// total message size (optional)
	ContentLength uint64
}

Response to an invocation

func CDecodeInvocationResponse added in v0.1.2

func CDecodeInvocationResponse(d *cbor.Decoder) (InvocationResponse, error)

CDecodeInvocationResponse deserializes a InvocationResponse using cbor

func MDecodeInvocationResponse added in v0.1.2

func MDecodeInvocationResponse(d *msgpack.Decoder) (InvocationResponse, error)

MDecodeInvocationResponse deserializes a InvocationResponse using msgpack

func (*InvocationResponse) CEncode added in v0.1.2

func (o *InvocationResponse) CEncode(encoder cbor.Writer) error

CEncode serializes a InvocationResponse using cbor

func (*InvocationResponse) MEncode added in v0.1.2

func (o *InvocationResponse) MEncode(encoder msgpack.Writer) error

MEncode serializes a InvocationResponse using msgpack

type LinkDefinition

type LinkDefinition struct {
	// actor public key
	ActorId string
	// provider public key
	ProviderId string
	// link name
	LinkName string
	// contract id
	ContractId string
	Values     LinkSettings
}

Link definition for binding actor to provider

func CDecodeLinkDefinition added in v0.1.2

func CDecodeLinkDefinition(d *cbor.Decoder) (LinkDefinition, error)

CDecodeLinkDefinition deserializes a LinkDefinition using cbor

func MDecodeLinkDefinition added in v0.1.2

func MDecodeLinkDefinition(d *msgpack.Decoder) (LinkDefinition, error)

MDecodeLinkDefinition deserializes a LinkDefinition using msgpack

func (*LinkDefinition) CEncode added in v0.1.2

func (o *LinkDefinition) CEncode(encoder cbor.Writer) error

CEncode serializes a LinkDefinition using cbor

func (*LinkDefinition) MEncode added in v0.1.2

func (o *LinkDefinition) MEncode(encoder msgpack.Writer) error

MEncode serializes a LinkDefinition using msgpack

type LinkSettings

type LinkSettings map[string]string

Settings associated with an actor-provider link

func CDecodeLinkSettings added in v0.1.2

func CDecodeLinkSettings(d *cbor.Decoder) (LinkSettings, error)

CDecodeLinkSettings deserializes a LinkSettings using cbor

func MDecodeLinkSettings added in v0.1.2

func MDecodeLinkSettings(d *msgpack.Decoder) (LinkSettings, error)

MDecodeLinkSettings deserializes a LinkSettings using msgpack

func (*LinkSettings) CEncode added in v0.1.2

func (o *LinkSettings) CEncode(encoder cbor.Writer) error

CEncode serializes a LinkSettings using cbor

func (*LinkSettings) MEncode added in v0.1.2

func (o *LinkSettings) MEncode(encoder msgpack.Writer) error

MEncode serializes a LinkSettings using msgpack

type Message

type Message struct {
	Method string
	Arg    []byte
}

Message contains an rpc operation name and a binary (serialized) payload

type RpcError

type RpcError struct {
	// contains filtered or unexported fields
}

RpcError is an error type emitted by the rpc infrastructure

func NewRpcError

func NewRpcError(kind string, message string) *RpcError

NewRpcError constructs an RpcError

func (*RpcError) Error

func (e *RpcError) Error() string

Error is RpcError's implementation of the error interface

type ServiceDispatch

type ServiceDispatch interface {
	// dispatch calls the actor's registered handler for the operation
	Dispatch(ctx *Context, actor interface{}, message *Message) (*Message, error)
}

ServiceDispatch defines the interface that all Receivers implement

type Timestamp

type Timestamp struct {
	// the number of non-leap seconds since unix epoch in UTC
	Sec int64
	// the number of nanoseconds since the beginning of the last whole non-leap second
	Nsec uint32
}

Timestamp identifies an instant in time

func CDecodeTimestamp added in v0.1.2

func CDecodeTimestamp(d *cbor.Decoder) (Timestamp, error)

CDecodeTimestamp deserializes a Timestamp using cbor

func MDecodeTimestamp added in v0.1.2

func MDecodeTimestamp(d *msgpack.Decoder) (Timestamp, error)

MDecodeTimestamp deserializes a Timestamp using msgpack

func (*Timestamp) CEncode added in v0.1.2

func (o *Timestamp) CEncode(encoder cbor.Writer) error

CEncode serializes a Timestamp using cbor

func (*Timestamp) MEncode added in v0.1.2

func (o *Timestamp) MEncode(encoder msgpack.Writer) error

MEncode serializes a Timestamp using msgpack

type TraceContext

type TraceContext map[string]string

Environment settings for initializing a capability provider

func CDecodeTraceContext added in v0.1.2

func CDecodeTraceContext(d *cbor.Decoder) (TraceContext, error)

CDecodeTraceContext deserializes a TraceContext using cbor

func MDecodeTraceContext added in v0.1.2

func MDecodeTraceContext(d *msgpack.Decoder) (TraceContext, error)

MDecodeTraceContext deserializes a TraceContext using msgpack

func (*TraceContext) CEncode added in v0.1.2

func (o *TraceContext) CEncode(encoder cbor.Writer) error

CEncode serializes a TraceContext using cbor

func (*TraceContext) MEncode added in v0.1.2

func (o *TraceContext) MEncode(encoder msgpack.Writer) error

MEncode serializes a TraceContext using msgpack

type Transport

type Transport struct {
	// contains filtered or unexported fields
}

Transport interface used to send rpc messages over some connection

func ToActor

func ToActor(actor_id string) Transport

ToActor constructs a Transport for actor-to-actor calls

func ToProvider

func ToProvider(contractId string, linkName string) Transport

ToProvider constructs a Transport for actor-to-provider calls

func (*Transport) Send

func (t *Transport) Send(ctx *Context, msg Message) ([]byte, error)

Send sends the rpc Message using a Transport

type U16

type U16 int16

unsigned 16-bit int

type U32

type U32 int32

unsigned 32-bit int

type U64

type U64 int64

unsigned 64-bit int

type U8

type U8 int8

unsigned byte

type Unit

type Unit struct {
}

Unit type

func CDecodeUnit added in v0.1.2

func CDecodeUnit(d *cbor.Decoder) (Unit, error)

CDecodeUnit deserializes a Unit using cbor

func MDecodeUnit added in v0.1.2

func MDecodeUnit(d *msgpack.Decoder) (Unit, error)

MDecodeUnit deserializes a Unit using msgpack

func (*Unit) CEncode added in v0.1.2

func (o *Unit) CEncode(encoder cbor.Writer) error

CEncode serializes a Unit using cbor

func (*Unit) MEncode added in v0.1.2

func (o *Unit) MEncode(encoder msgpack.Writer) error

MEncode serializes a Unit using msgpack

type WasmCloudEntity

type WasmCloudEntity struct {
	PublicKey  string
	LinkName   string
	ContractId CapabilityContractId
}

func CDecodeWasmCloudEntity added in v0.1.2

func CDecodeWasmCloudEntity(d *cbor.Decoder) (WasmCloudEntity, error)

CDecodeWasmCloudEntity deserializes a WasmCloudEntity using cbor

func MDecodeWasmCloudEntity added in v0.1.2

func MDecodeWasmCloudEntity(d *msgpack.Decoder) (WasmCloudEntity, error)

MDecodeWasmCloudEntity deserializes a WasmCloudEntity using msgpack

func (*WasmCloudEntity) CEncode added in v0.1.2

func (o *WasmCloudEntity) CEncode(encoder cbor.Writer) error

CEncode serializes a WasmCloudEntity using cbor

func (*WasmCloudEntity) MEncode added in v0.1.2

func (o *WasmCloudEntity) MEncode(encoder msgpack.Writer) error

MEncode serializes a WasmCloudEntity using msgpack

Directories

Path Synopsis
example module

Jump to

Keyboard shortcuts

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