spi

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecValueFunctionOnPluginGoRoutine

func ExecValueFunctionOnPluginGoRoutine[R any](
	container IPMAASContainer,
	f func() R,
	defaultValueFn func() R,
	errorMessage string) (R, error)

Types

type CompiledTemplate

type CompiledTemplate struct {
	Instance ITemplate
	Styles   []string
	Scripts  []string
}

type EntityInvocationHandlerFunc

type EntityInvocationHandlerFunc func(func(entity any)) error

type EntityRenderFunc

type EntityRenderFunc func(entity any) (string, error)

type EntityRenderer

type EntityRenderer struct {
	RenderFunc          EntityRenderFunc
	StreamingRenderFunc StreamingEntityRenderFunc
	Styles              []string
	Scripts             []string
}

func TemplateBasedRendererFactory

func TemplateBasedRendererFactory(
	container IPMAASContainer,
	templateInfo *TemplateInfo,
	typeCheckFn func(any) bool,
	typeName string) (EntityRenderer, error)

type EntityRendererFactory

type EntityRendererFactory func() (EntityRenderer, error)

type EntityStubFactoryFunc

type EntityStubFactoryFunc func() (any, error)

type IPMAASContainer

type IPMAASContainer interface {
	AddRoute(path string, handlerFunc http.HandlerFunc)
	BroadcastEvent(entityEventId string, event any) error
	RenderList(w http.ResponseWriter, r *http.Request, options RenderListOptions, items []interface{})
	GetTemplate(templateInfo *TemplateInfo) (CompiledTemplate, error)
	GetEntityRenderer(entityType reflect.Type) (EntityRenderer, error)
	RegisterEntityRenderer(entityType reflect.Type, renderFactory EntityRendererFactory)
	EnableStaticContent(staticContentDir string)

	// ProvideContentFS Registers an io/fs.FS instance that the server can use to read plugin resources such as
	// templates or static file content for serving over HTTP.
	ProvideContentFS(fs fs.FS, prefix string)

	// RegisterEntity Registers an entity with server.  This gives it a unique name, which can later be looked up for
	// further interaction with the entity.
	RegisterEntity(
		uniqueData string,
		entityType reflect.Type,
		name string,
		stubFactoryFn EntityStubFactoryFunc) (string, error)

	// DeregisterEntity Removes an entity previously registered with the server.  Pass the ID returned from the
	// previous call to RegisterEntity.
	DeregisterEntity(id string) error

	// AssertEntityType Verifies that an entity with the given ID exists and is of the passed type
	AssertEntityType(pmaasEntityId string, entityType reflect.Type) error

	// GetEntities Returns a list of entities that match the supplied predicate.
	GetEntities(predicate func(info *entity.RegisteredEntityInfo) bool) ([]entity.RegisteredEntityInfo, error)

	// InvokeOnEntity Invokes the supplied function on the plugin-runner goroutine of the plugin that owns the specified
	//entity, supplying the entity.
	InvokeOnEntity(id string, function func(entity any)) error

	// RegisterEventReceiver Registers a receiver for events.  If successful, returns an integer handle that can be used
	// to deregister the handler in the future.
	RegisterEventReceiver(predicate events.EventPredicate, receiver events.EventReceiver) (int, error)

	// DeregisterEventReceiver Removes a previously registered event receiver
	DeregisterEventReceiver(receiverHandle int) error

	// EnqueueOnPluginGoRoutine Enqueues the passed function for execution on the plugin's main GoRoutine.
	// Returns an error if the function cannot be enqueued.  This method returns as soon as the function
	// is enqueued, it does not wait for execution.  If you need the results of the execution, you'll need to
	// orchestrate that in the function.  For example, the function can send the result back via a channel.
	// Warning: Calling this function when already executing on the plugin's main GoRoutine will result in deadlock.
	EnqueueOnPluginGoRoutine(f func()) error

	// EnqueueOnServerGoRoutine Enqueues the passed functions for execution on the server's main GoRoutine.
	// The server's main GoRoutine is the one used to call PMAAS.Run().
	// Use this to execute callbacks registered during the server configuration phase.
	EnqueueOnServerGoRoutine(invocations []func()) error

	// ClosedCallbackChannel returns an already closed callback channel.  You can use this when you know
	// there will not be a need for any callbacks.
	ClosedCallbackChannel() chan func()
}

IPMAASContainer is an interface for plugins to interact with the PMAAS server.

type IPMAASPlugin

type IPMAASPlugin interface {
	Init(container IPMAASContainer)
	Start()
	Stop() chan func()
}

IPMAASPlugin is the interface all plugins must implement. The core will call Init, Start, and Stop in sequence, all from the same go routine.

All of these functions will be called on the plugin's main goroutine.

The Stop function must not block. If there is blocking work to be done, do the work in a new or separate goroutine, and inform the server that it's complete by closing the returned channel. The Stop function can also request additional callbacks by sending functions to the returned channel.

type IPMAASRenderPlugin

type IPMAASRenderPlugin interface {
	IPMAASPlugin
	RenderList(w http.ResponseWriter, r *http.Request, options RenderListOptions, items []interface{})
}

type IPMAASTemplateEnginePlugin

type IPMAASTemplateEnginePlugin interface {
	IPMAASPlugin
	GetTemplate(templateInfo *TemplateInfo) (CompiledTemplate, error)
}

type ITemplate

type ITemplate interface {
	Execute(wr io.Writer, data any) error
}

type RenderListOptions

type RenderListOptions struct {
	Title  string
	Header any
}

type StreamingEntityRenderFunc

type StreamingEntityRenderFunc func(w io.Writer, entity any) error

type TemplateInfo

type TemplateInfo struct {
	Name     string
	FuncMap  template.FuncMap
	Paths    []string
	Scripts  []string
	Styles   []string
	SourceFS fs.FS
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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