resource

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: AGPL-3.0 Imports: 5 Imported by: 5

Documentation

Overview

Package resource interfaces retrieval of bytecode, output templates and external code execution.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CodeFunc

type CodeFunc func(ctx context.Context, nodeSym string) ([]byte, error)

CodeFunc is the function signature for retrieving bytecode for a given symbol.

type DbResource

type DbResource struct {
	*MenuResource
	// contains filtered or unexported fields
}

DbResource is a MenuResource that uses the given db.Db implementation as data retriever.

It implements the Resource interface.

The DbResource can resolve any db.DATATYPE_* if instructed to do so.

func NewDbResource

func NewDbResource(store db.Db) *DbResource

NewDbResource instantiates a new DbResource

By default it will handle db.DATATYPE_TEPMLATE, db.DATATYPE_MENU and db.DATATYPE_BIN.

func (*DbResource) Close

func (g *DbResource) Close() error

Close implements the Resource interface.

func (*DbResource) DbFuncFor

func (g *DbResource) DbFuncFor(ctx context.Context, sym string) (EntryFunc, error)

The method will first attempt to resolve using the function registered with the MenuResource parent class.

If no match is found, and if support for db.DATATYPE_STATICLOAD has been enabled, an additional lookup will be performed using the underlying db.

By default bound to FuncFor. Can be replaced with WithEntryFuncGetter.

func (*DbResource) DbGetCode

func (g *DbResource) DbGetCode(ctx context.Context, sym string) ([]byte, error)

Will fail if support for db.DATATYPE_BIN has been disabled.

By default bound to GetCode. Can be replaced with WithCodeGetter.

func (*DbResource) DbGetMenu

func (g *DbResource) DbGetMenu(ctx context.Context, sym string) (string, error)

Will fail if support for db.DATATYPE_MENU has been disabled.

By default bound to GetMenu. Can be replaced with WithMenuGetter.

func (*DbResource) DbGetTemplate

func (g *DbResource) DbGetTemplate(ctx context.Context, sym string) (string, error)

Will fail if support for db.DATATYPE_TEMPLATE has been disabled.

By default bound to GetTemplate. Can be replaced with WithTemplateGetter.

func (*DbResource) With

func (g *DbResource) With(typ uint8) *DbResource

Without is a chainable function that enables handling of the given data type.

func (*DbResource) WithOnly

func (g *DbResource) WithOnly(typ uint8) *DbResource

WithOnly is a chainable convenience function that disables handling of all except the given data type.

func (*DbResource) Without

func (g *DbResource) Without(typ uint8) *DbResource

Without is a chainable function that disables handling of the given data type.

type EntryFunc

type EntryFunc func(ctx context.Context, nodeSym string, input []byte) (Result, error)

EntryFunc is a function signature for a function that resolves the symbol of a LOAD instruction.

The EntryFunc receives the current input buffer from the client, aswell as the symbol of the current state node being executed.

The implementer MUST NOT modify state flags or cache inside the function. The resource.Result object MUST be used instead.

type FuncForFunc

type FuncForFunc func(ctx context.Context, loadSym string) (EntryFunc, error)

FuncForFunc is a function that returns an EntryFunc associated with a LOAD instruction symbol.

type MenuFunc func(ctx context.Context, menuSym string) (string, error)

MenuFunc is the function signature for retrieving menu symbol resolution.

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

MenuResource contains the base definition for building Resource implementations.

func NewMenuResource

func NewMenuResource() *MenuResource

NewMenuResource creates a new MenuResource instance.

func (m *MenuResource) AddLocalFunc(sym string, fn EntryFunc)

AddLocalFunc associates a handler function with a external function symbol to be returned by FallbackFunc.

func (m *MenuResource) Close() error

Close implements the Resource interface.

func (m *MenuResource) FallbackFunc(ctx context.Context, sym string) (EntryFunc, error)

FallbackFunc returns the default handler function for a given external function symbol.

func (m *MenuResource) FuncFor(ctx context.Context, sym string) (EntryFunc, error)

FuncFor implements Resource interface.

func (m *MenuResource) GetCode(ctx context.Context, sym string) ([]byte, error)

GetCode implements Resource interface.

func (m *MenuResource) GetMenu(ctx context.Context, sym string) (string, error)

GetMenu implements Resource interface.

func (m *MenuResource) GetTemplate(ctx context.Context, sym string) (string, error)

GetTemplate implements Resource interface.

func (m *MenuResource) WithCodeGetter(codeGetter CodeFunc) *MenuResource

WithCodeGetter sets the code symbol resolver method.

func (m *MenuResource) WithEntryFuncGetter(entryFuncGetter FuncForFunc) *MenuResource

WithEntryGetter sets the content symbol resolver getter method.

func (m *MenuResource) WithMenuGetter(menuGetter MenuFunc) *MenuResource

WithMenuGetter sets the menu symbol resolver method.

func (m *MenuResource) WithTemplateGetter(templateGetter TemplateFunc) *MenuResource

WithTemplateGetter sets the template symbol resolver method.

type Resource

type Resource interface {
	// GetTemplate retrieves a render template associated with the given symbol.
	GetTemplate(ctx context.Context, nodeSym string) (string, error)
	// GetCode retrieves the bytecode associated with the given symbol.
	GetCode(ctx context.Context, nodeSym string) ([]byte, error)
	// GetMenu retrieves the menu label associated with the given symbol.
	GetMenu(ctx context.Context, menuSym string) (string, error)
	// FuncFor retrieves the external function (EntryFunc) associated with the given symbol.
	FuncFor(ctx context.Context, loadSym string) (EntryFunc, error)
	// Close implements the io.Closer interface.
	//
	// Safely shuts down retrieval backend.
	Close() error
}

Resource implementation are responsible for retrieving values and templates for symbols, and can render templates from value dictionaries.

All methods must fail if the symbol cannot be resolved.

type Result

type Result struct {
	// content value for symbol after execution.
	Content string
	// application defined status code which can complement error returns
	Status int
	// request caller to set error flags at given indices.
	FlagSet []uint32
	// request caller to reset error flags at given indices.
	FlagReset []uint32
}

Result contains the results of an external code operation.

type TemplateFunc

type TemplateFunc func(ctx context.Context, nodeSym string) (string, error)

TemplateFunc is the function signature for retrieving a render template for a given symbol.

Jump to

Keyboard shortcuts

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