loaders

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// wrap helpers
	WrapExprType    = "Wrap"
	BeforeExprType  = "Before"
	SuccessExprType = "Success"

	// decision
	DecisionExprType = "Decision"
	CaseExprType     = "Case"

	//others
	StepExprType    = "Step"
	FailureExprType = "Failure"
)

Variables

View Source
var (
	ErrNoExpr = errors.New("no expr in args")
)

Functions

func Default

func Default() map[string]ComponentLoadFunc

Loaders for components from github.com/GettEngineering/effe/types package

func FindCallExprWithType

func FindCallExprWithType(args []ast.Expr, exprType string) (*ast.CallExpr, int, error)

func LoadCaseComponent

func LoadCaseComponent(
	caseCallExpr *ast.CallExpr,
	f FlowLoader,
) (types.Component, error)

LoadCaseComponent converts an expression declared with effe.Case to a component with type types.CaseComponent

func LoadComponentsWithTypes

func LoadComponentsWithTypes(exprs []ast.Expr, f FlowLoader, typeStrings ...string) (map[string]types.Component, []ast.Expr, error)

LoadComponentsWithTypes parses expressions in first argument and searches expressions with types in last argument. After that this method execute a method LoadComponent for each component and returns a set of components. Key is a string representation of the type.

func LoadDecisionComponent

func LoadDecisionComponent(effeDecisionFuncCall *ast.CallExpr, f FlowLoader) (types.Component, error)

LoadDecisionComponent converts an expression declared with effe.Decision to a component with type types.DecisionComponent

func LoadSimpleComponent

func LoadSimpleComponent(effeStepFuncCall *ast.CallExpr, f FlowLoader) (types.Component, error)

LoadSimpleComponent converts an expression declared with effe.Step to a component with type types.SimpleComponent

func LoadWrapComponent

func LoadWrapComponent(effeWrapFuncCall *ast.CallExpr, f FlowLoader) (types.Component, error)

LoadWrapComponent converts an expression declared with effe.Wrap to a component with type types.WrapComponent

func NewComponentsFromArgs

func NewComponentsFromArgs(args []ast.Expr, f FlowLoader) ([]types.Component, error)

func ParseAndRemoveServiceComponents

func ParseAndRemoveServiceComponents(exprs []ast.Expr, types ...string) (map[string]*ast.CallExpr, []ast.Expr, error)

func RemoveExprByIndex

func RemoveExprByIndex(exprs []ast.Expr, index int) []ast.Expr

Types

type ComponentLoadFunc

type ComponentLoadFunc func(*ast.CallExpr, FlowLoader) (types.Component, error)

Type for loaders uses in Loader.

type FlowLoader

type FlowLoader interface {
	LoadComponent(call *ast.CallExpr) (types.Component, error)
	GetFuncDecl(string) (*ast.FuncDecl, bool)
}

FlowLoader provides functions which use in Loader. It's a helper for easy reusing existed code

type Loader

type Loader interface {
	// LoadFlow takes array of expressions and set of function declartions and returns an
	// array of components and a failure component.
	LoadFlow([]ast.Expr, map[string]*ast.FuncDecl) ([]types.Component, types.Component, error)

	// Adds new handler by type here.
	Register(apiExtType string, c ComponentLoadFunc) error

	// Returns a declaration of function by name
	GetFuncDecl(name string) (*ast.FuncDecl, bool)
}

Loader converts flow expressions to components

func NewLoader

func NewLoader(opts ...Option) Loader

Initializes a new Loader

type Option

type Option func(l *loader)

func WithLoaders

func WithLoaders(loaders map[string]ComponentLoadFunc) Option

WithLoaders is used for settings new loaders in a Loader. Default loaders are used from the method DefaultLoader

func WithPackages

func WithPackages(packages []string) Option

WithPackages is used for checking permitted packages which are used in DSL. It is necessary because you can add a custom expression type.

Example

func BuildMyBusinessFlow(){
      effe.BuildFLow(
        effe.Step(step1),
        custompkg.MyStep(step2),
      )
}

// You need custompkg to loader packages
gen := generator.NewGenerator(
    generator.WithSetttings(settings),
    generator.WithLoader(loaders.NewLoader(loaders.WithPackages([]string{"effe", "custompkg"}))),
    generator.WithDrawer(drawer.NewDrawer()),
    generator.WithStrategy(
        strategies.NewChain(strategies.WithServiceObjectName(settings.LocalInterfaceVarname())),
    ),
)

Jump to

Keyboard shortcuts

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