engine

package
v0.0.0-...-6932d60 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

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

func New

func New(options ...func(engineOptions *Options)) *Engine

New returns a new engine

func (*Engine) Run

func (g *Engine) Run(parentCtx context.Context, fn fnfile.FnDef) error
Example (Defer)
out := bytes.Buffer{}
errOut := bytes.Buffer{}

eng := setupEngine(&out, &errOut)

ctx := context.TODO()

fn := fnfile.FnDef{
	Name: "test",
	Do: fnfile.Do{
		Steps: fnfile.Steps{
			fnfile.DeferSpec{
				Do: fnfile.Do{
					Steps: fnfile.Steps{
						fnfile.Sh{
							Run: `echo "defer 1: Sub steps of a defer step..."`,
						},
						fnfile.Sh{
							Run: `echo "defer 1: run sequentially"`,
						},
					},
				},
			},
			fnfile.DeferSpec{
				Do: fnfile.Do{
					Steps: fnfile.Steps{
						fnfile.Sh{
							Run: `echo "defer 2: Deferred function calls are executed in Last In First Out order. This should show up first."`,
						},
					},
				},
			},
			fnfile.Sh{
				Run: `echo "Hello, World"`,
			},
		},
	},
}

panicOnError(eng.Run(ctx, fn))

fmt.Print(out.String())
Output:

Hello, World
defer 2: Deferred function calls are executed in Last In First Out order. This should show up first.
defer 1: Sub steps of a defer step...
defer 1: run sequentially
Example (Do_nested)
out := bytes.Buffer{}
errOut := bytes.Buffer{}

eng := setupEngine(&out, &errOut)

ctx := context.TODO()

fn := fnfile.FnDef{
	Name: "test",
	Do: fnfile.Do{
		Steps: fnfile.Steps{
			fnfile.Sh{
				Run: `echo "one"`,
			},
			fnfile.Do{
				Steps: fnfile.Steps{
					fnfile.Sh{
						Run: `echo "nested two"`,
					},
				},
			},
			fnfile.Sh{
				Run: `echo "three"`,
			},
		},
	},
}

panicOnError(eng.Run(ctx, fn))

fmt.Println(out.String())
Output:

one
nested two
three
Example (Do_sh)
out := bytes.Buffer{}
errOut := bytes.Buffer{}

eng := setupEngine(&out, &errOut)

ctx := context.TODO()

fn := fnfile.FnDef{
	Name: "test",
	Do: fnfile.Do{
		Steps: fnfile.Steps{
			fnfile.Sh{
				Run: `echo "hello"`,
			},
		},
	},
}

panicOnError(eng.Run(ctx, fn))

fmt.Println(out.String())
Output:

hello
Example (Do_stop_on_failure)
out := bytes.Buffer{}
errOut := bytes.Buffer{}

eng := setupEngine(&out, &errOut)

ctx := context.TODO()

fn := fnfile.FnDef{
	Name: "test",
	Do: fnfile.Do{
		Steps: fnfile.Steps{
			fnfile.Sh{
				Run: `echo "first"`,
			},
			fnfile.Sh{
				Run: `false`,
			},
			fnfile.Sh{
				Run: `echo "last"`,
			},
		},
	},
}

err := eng.Run(ctx, fn)

fmt.Printf("result: %s, error: %s", strings.TrimSpace(out.String()), err)
Output:

result: first, error: 1 error occurred:
	* running sh [false]: exit status 1

type FileFinder

type FileFinder func(dir string, fs StatReadFS) ([]byte, error)

func AmbiguousExtensionFileFinder

func AmbiguousExtensionFileFinder(name string, extensions ...string) FileFinder

type Options

type Options struct {
	Writer fnfile.ResponseWriter
}

type Reader

type Reader func() (fnfile.FnFile, error)

func YamlFileReader

func YamlFileReader(options ...func(readerOptions *YamlFileReaderOptions)) Reader

type StatReadFS

type StatReadFS interface {
	fs.StatFS
	fs.ReadFileFS
}

type YamlFileReaderOptions

type YamlFileReaderOptions struct {
	FS         StatReadFS
	FileFinder FileFinder
}

Jump to

Keyboard shortcuts

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