base

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParamListToParamMap

func ParamListToParamMap(args []string) map[string]string

ParamListToParamMap is a helper function that converts a list of strings to a map of strings (key==value)

Types

type Context

type Context struct {
	UUID uuid.UUID
	// contains filtered or unexported fields
}

Context keeps the runtime data of a graph execution tree

func NewContext

func NewContext(logger log.FieldLogger) *Context

NewContext creates a Context with a given logger

func (*Context) GetID

func (c *Context) GetID() string

GetID returns the string represantation of the ID for this execution tree

func (*Context) GetLogger

func (c *Context) GetLogger() log.FieldLogger

GetLogger returns a Logger with the proper fields added to identify the context

type FreepsBaseOperator

type FreepsBaseOperator interface {
	Execute(ctx *Context, fn string, mainArgs map[string]string, mainInput *OperatorIO) *OperatorIO

	GetFunctions() []string // returns a list of functions that this operator can execute
	GetPossibleArgs(fn string) []string
	GetArgSuggestions(fn string, arg string, otherArgs map[string]string) map[string]string
	GetName() string

	GetHook() interface{}
	StartListening(*Context)
	Shutdown(*Context)
}

FreepsBaseOperator provides the interface for all operators used by the graph module Operators can either implement this interface directly or use MakeFreepsOperator to convert a struct into an operator

func MakeFreepsOperators

func MakeFreepsOperators(anyClass FreepsOperator, cr *utils.ConfigReader, ctx *Context) []FreepsBaseOperator

MakeFreepsOperators creates FreepsBaseOperator variations from any struct that implements FreepsOperator

type FreepsExampleOperator

type FreepsExampleOperator struct{}

func (*FreepsExampleOperator) ExecuteDynamic

func (feo *FreepsExampleOperator) ExecuteDynamic(ctx *Context, fn string, mainArgs FunctionArguments, mainInput *OperatorIO) *OperatorIO

func (*FreepsExampleOperator) GetDefaultConfig

func (feo *FreepsExampleOperator) GetDefaultConfig() interface{}

func (*FreepsExampleOperator) GetDynamicArgSuggestions

func (feo *FreepsExampleOperator) GetDynamicArgSuggestions(fn string, arg string, otherArgs FunctionArguments) map[string]string

func (*FreepsExampleOperator) GetDynamicFunctions

func (feo *FreepsExampleOperator) GetDynamicFunctions() []string

func (*FreepsExampleOperator) GetDynamicPossibleArgs

func (feo *FreepsExampleOperator) GetDynamicPossibleArgs(fn string) []string

func (*FreepsExampleOperator) GetHook

func (feo *FreepsExampleOperator) GetHook() interface{}

func (*FreepsExampleOperator) InitCopyOfOperator

func (feo *FreepsExampleOperator) InitCopyOfOperator(ctx *Context, config interface{}, fullOperatorName string) (FreepsOperatorWithConfig, error)

func (*FreepsExampleOperator) Shutdown

func (feo *FreepsExampleOperator) Shutdown(ctx *Context)

func (*FreepsExampleOperator) StartListening

func (feo *FreepsExampleOperator) StartListening(ctx *Context)

type FreepsFunctionMetaData

type FreepsFunctionMetaData struct {
	FuncValue reflect.Value
	Name      string
	FuncType  FreepsFunctionType
}

FreepsFunctionMetaData contains the reflect Value to the Function itself, the case sensitive name and the FreepsFunctionType

type FreepsFunctionParameters

type FreepsFunctionParameters interface {
	// GetArgSuggestions returns a map of possible arguments for the given function and argument name
	GetArgSuggestions(operator FreepsOperator, fn string, argName string, otherArgs map[string]string) map[string]string

	// VerifyParameters checks if the given parameters are valid
	VerifyParameters(operator FreepsOperator) *OperatorIO
}

FreepsFunctionParameters is the interface for a paramter struct that can return ArgumentSuggestions

type FreepsFunctionParametersWithInit

type FreepsFunctionParametersWithInit interface {
	Init(ctx *Context, operator FreepsOperator, fn string)
}

FreepsFunctionParametersWithInit adds the Init() method to FreepsFunctionParameters

type FreepsFunctionType

type FreepsFunctionType int

FreepsFunctionType is an enum that indicates how many function parameters a compatible FreepsFunction has

const (
	// FreepsFunctionTypeUnknown indicates that the function is not a FreepsFunction
	FreepsFunctionTypeUnknown FreepsFunctionType = iota
	// FreepsFunctionTypeSimple indicates that the function has no parameters
	FreepsFunctionTypeSimple
	// FreepsFunctionTypeContextOnly indicates that the function has a Context ptr as first parameter
	FreepsFunctionTypeContextOnly
	// FreepsFunctionTypeContextAndInput indicates that the function has a Context ptr as first parameter and a OperatorIO ptr as second parameter
	FreepsFunctionTypeContextAndInput
	// FreepsFunctionTypeWithDynamicFunctionArguments indicates that the function has a Context ptr as first parameter, a OperatorIO ptr as second parameter and FunctionArguments as third parameter
	FreepsFunctionTypeWithDynamicFunctionArguments
	// FreepsFunctionTypeWithArguments indicates that the function has a Context ptr as first parameter, a OperatorIO ptr as second parameter and a struct as third parameter
	FreepsFunctionTypeWithArguments
	// FreepsFunctionTypeFullSignature indicates that the function has a Context ptr as first parameter, a OperatorIO ptr as second parameter, a struct as third parameter and a map[string]string as fourth parameter
	FreepsFunctionTypeFullSignature
)

type FreepsOperator

type FreepsOperator interface {
}

FreepsOperator is the interface structs need to implement so FreepsOperatorWrapper can create a FreepsOperator from them

type FreepsOperatorWithConfig

type FreepsOperatorWithConfig interface {
	FreepsOperator
	// GetDefaultConfig returns a copy of the default config
	GetDefaultConfig() interface{}
	// InitCopyOfOperator creates a copy of the operator and initializes it with the given config
	InitCopyOfOperator(ctx *Context, config interface{}, fullOperatorName string) (FreepsOperatorWithConfig, error)
}

FreepsOperatorWithConfig adds methods to support multiple configurations to FreepsOperator

type FreepsOperatorWithDynamicFunctions

type FreepsOperatorWithDynamicFunctions interface {
	FreepsOperator
	// GetDynamicFunctions returns a list of functions that are dynamically added to the operator
	GetDynamicFunctions() []string
	// GetDynamicPossibleArgs returns a list of possible arguments for the given function
	GetDynamicPossibleArgs(fn string) []string
	// GetDynamicArgSuggestions returns a map of possible arguments for the given function and argument name
	GetDynamicArgSuggestions(fn string, arg string, otherArgs FunctionArguments) map[string]string
	// ExecuteDynamic executes the given function with the given arguments
	ExecuteDynamic(ctx *Context, fn string, mainArgs FunctionArguments, mainInput *OperatorIO) *OperatorIO
}

FreepsOperatorWithDynamicFunctions adds methods to support dynamic functions to FreepsOperator

type FreepsOperatorWithHook

type FreepsOperatorWithHook interface {
	FreepsOperator
	// GetHook returns the hook for this operator
	GetHook() interface{}
}

FreepsOperatorWithShutdown adds the Shutdown() method to FreepsOperatorWithConfig

type FreepsOperatorWithShutdown

type FreepsOperatorWithShutdown interface {
	FreepsOperator
	// StartListening is called when the graph engine is starting up
	StartListening(ctx *Context)
	// Shutdown is called when the graph engine is shutting down
	Shutdown(ctx *Context)
}

FreepsOperatorWithShutdown adds the Shutdown() method to FreepsOperatorWithConfig

type FreepsOperatorWrapper

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

FreepsOperatorWrapper creates everything necessary to be a FreepsBaseOperator from any struct that implements FreepsOperator

func (*FreepsOperatorWrapper) Execute

func (o *FreepsOperatorWrapper) Execute(ctx *Context, function string, args map[string]string, mainInput *OperatorIO) *OperatorIO

Execute gets the FreepsFunction by name, assignes all parameters based on the args map and calls the function

func (*FreepsOperatorWrapper) GetArgSuggestions

func (o *FreepsOperatorWrapper) GetArgSuggestions(function string, argName string, otherArgs map[string]string) map[string]string

GetArgSuggestions creates a Freepsfunction by name and returns the suggestions for the argument argName

func (*FreepsOperatorWrapper) GetCommonParameterSuggestions

func (o *FreepsOperatorWrapper) GetCommonParameterSuggestions(parmStruct reflect.Value, paramName string) []string

GetCommonParameterSuggestions returns the default suggestions for the argument argName of type argType

func (*FreepsOperatorWrapper) GetConfig

func (o *FreepsOperatorWrapper) GetConfig() interface{}

GetConfig returns the config of the operator

func (*FreepsOperatorWrapper) GetFunctions

func (o *FreepsOperatorWrapper) GetFunctions() []string

GetFunctions returns all methods of the opClass

func (*FreepsOperatorWrapper) GetHook

func (o *FreepsOperatorWrapper) GetHook() interface{}

GetHook returns the hook of the FreepsOperator if it exists

func (*FreepsOperatorWrapper) GetName

func (o *FreepsOperatorWrapper) GetName() string

GetName returns the name of the struct opClass

func (*FreepsOperatorWrapper) GetPossibleArgs

func (o *FreepsOperatorWrapper) GetPossibleArgs(fn string) []string

GetPossibleArgs returns all function parameters

func (*FreepsOperatorWrapper) SetOptionalFreepsFunctionParameters

func (o *FreepsOperatorWrapper) SetOptionalFreepsFunctionParameters(freepsFuncParams reflect.Value, args map[string]string, failOnErr bool) *OperatorIO

SetOptionalFreepsFunctionParameters sets the parameters of the FreepsFunction based on the args map

func (*FreepsOperatorWrapper) SetRequiredFreepsFunctionParameters

func (o *FreepsOperatorWrapper) SetRequiredFreepsFunctionParameters(freepsFuncParams reflect.Value, args map[string]string, failOnErr bool) *OperatorIO

SetRequiredFreepsFunctionParameters sets the parameters of the FreepsFunction based on the args map

func (*FreepsOperatorWrapper) Shutdown

func (o *FreepsOperatorWrapper) Shutdown(ctx *Context)

Shutdown calls the Shutdown method of the FreepsOperator if it exists

func (*FreepsOperatorWrapper) StartListening

func (o *FreepsOperatorWrapper) StartListening(ctx *Context)

StartListening calls the StartListening method of the FreepsOperator if it exists

type FunctionArguments

type FunctionArguments = utils.CIMap[string]

FunctionArguments is a struct that can be used to pass arguments to a function

func MakeEmptyFunctionArguments

func MakeEmptyFunctionArguments() FunctionArguments

func NewFunctionArguments

func NewFunctionArguments(args map[string]string) FunctionArguments

type OperatorIO

type OperatorIO struct {
	OutputType  OutputT
	HTTPCode    int
	Output      interface{}
	ContentType string `json:",omitempty"`
}

OperatorIO is the input and output of an operator, once created it should not be modified Note: the Store Operator depends on this struct being immutable

func MakeByteOutput

func MakeByteOutput(output []byte) *OperatorIO

func MakeByteOutputWithContentType

func MakeByteOutputWithContentType(output []byte, contentType string) *OperatorIO

func MakeEmptyOutput

func MakeEmptyOutput() *OperatorIO

func MakeObjectOutput

func MakeObjectOutput(output interface{}) *OperatorIO

func MakeObjectOutputWithContentType

func MakeObjectOutputWithContentType(output interface{}, contentType string) *OperatorIO

func MakeOutputError

func MakeOutputError(code int, msg string, a ...interface{}) *OperatorIO

func MakePlainOutput

func MakePlainOutput(msg string) *OperatorIO

func MakeSprintfOutput

func MakeSprintfOutput(msg string, a ...interface{}) *OperatorIO

func (*OperatorIO) GetArgsMap

func (io *OperatorIO) GetArgsMap() (map[string]string, error)

func (*OperatorIO) GetBytes

func (io *OperatorIO) GetBytes() ([]byte, error)

func (*OperatorIO) GetError

func (io *OperatorIO) GetError() error

func (*OperatorIO) GetObject

func (io *OperatorIO) GetObject() interface{}

func (*OperatorIO) GetSize

func (io *OperatorIO) GetSize() (int, error)

func (*OperatorIO) GetStatusCode

func (io *OperatorIO) GetStatusCode() int

func (*OperatorIO) GetString

func (io *OperatorIO) GetString() string

func (*OperatorIO) IsEmpty

func (io *OperatorIO) IsEmpty() bool

func (*OperatorIO) IsError

func (io *OperatorIO) IsError() bool

func (*OperatorIO) IsFormData

func (io *OperatorIO) IsFormData() bool

func (*OperatorIO) IsObject

func (io *OperatorIO) IsObject() bool

func (*OperatorIO) IsPlain

func (io *OperatorIO) IsPlain() bool

func (*OperatorIO) Log

func (oio *OperatorIO) Log(logger logrus.FieldLogger)

func (*OperatorIO) ParseFormData

func (io *OperatorIO) ParseFormData() (url.Values, error)

ParseFormData returns the data as posted by a HTML form

func (*OperatorIO) ParseJSON

func (io *OperatorIO) ParseJSON(obj interface{}) error

func (*OperatorIO) ToString

func (oio *OperatorIO) ToString() string

func (*OperatorIO) WriteTo

func (oio *OperatorIO) WriteTo(bwriter io.Writer) (int, error)

type OutputT

type OutputT string
const (
	Empty     OutputT = ""
	Error     OutputT = "error"
	PlainText OutputT = "plain"
	Byte      OutputT = "byte"
	Object    OutputT = "object"
)

Jump to

Keyboard shortcuts

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