diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml index 180b99d..f53ab11 100644 --- a/.github/workflows/go-test.yml +++ b/.github/workflows/go-test.yml @@ -40,7 +40,7 @@ jobs: - name: Lint uses: golangci/golangci-lint-action@v3 with: - version: v1.47.2 + version: v1.58.0 - name: Check diffs # --name-only first for debugging run: git diff --name-only && git diff --quiet diff --git a/checkers/unused/check.go b/checkers/unused/check.go index 055184a..6777e0a 100644 --- a/checkers/unused/check.go +++ b/checkers/unused/check.go @@ -16,8 +16,8 @@ func (e Error) Error() string { } // Check checks that all nodes are used in one way or another: -// - have only one error output -// - are used explicitly +// - have only one error output +// - are used explicitly func Check(graph goflow.GraphRenderer) error { nodes := graph.Nodes() diff --git a/example/generator/main.go b/example/generator/main.go index d4b4f97..7350ab6 100644 --- a/example/generator/main.go +++ b/example/generator/main.go @@ -5,7 +5,6 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "os" "path" "sort" @@ -111,7 +110,7 @@ func main() { continue } - if err := ioutil.WriteFile(generatedFilename, buf.Bytes(), 0o600); err != nil { + if err := os.WriteFile(generatedFilename, buf.Bytes(), 0o600); err != nil { genErrs = append(genErrs, err) } @@ -131,7 +130,7 @@ func main() { return n1 <= n2 }) handleErr(json.NewEncoder(&buf).Encode(nodes)) - handleErr(ioutil.WriteFile("nodes.json", buf.Bytes(), 0o600)) + handleErr(os.WriteFile("nodes.json", buf.Bytes(), 0o600)) var graphLoader gfgo.NodeLoader err = graphLoader.Load( @@ -153,7 +152,7 @@ func main() { err = goWriter.Flush() handleErr(err) - err = ioutil.WriteFile(pgFilename, buf.Bytes(), 0o600) + err = os.WriteFile(pgFilename, buf.Bytes(), 0o600) handleErr(err) } diff --git a/gfutil/find.go b/gfutil/find.go index b7197e6..7af2e49 100644 --- a/gfutil/find.go +++ b/gfutil/find.go @@ -1,13 +1,13 @@ package gfutil import ( - "io/ioutil" + "os" "path" "strings" ) func FindGraphFileNames(dir string) ([]string, error) { - files, err := ioutil.ReadDir(dir) + files, err := os.ReadDir(dir) if err != nil { return nil, err } diff --git a/gfutil/gfgo/nodes.go b/gfutil/gfgo/nodes.go index 0b62a94..5642973 100644 --- a/gfutil/gfgo/nodes.go +++ b/gfutil/gfgo/nodes.go @@ -406,7 +406,8 @@ func getDocFromPackage(pkg *packages.Package, pos token.Pos) string { // parseTypesDoc hacks the thing by grabbing info of types using doc. // TODO: review all this and improve if possible... -// shall we try with https://pkg.go.dev/go/ast?tab=doc#CommentGroup maybe? +// +// shall we try with https://pkg.go.dev/go/ast?tab=doc#CommentGroup maybe? func parseTypesDoc(pkg *packages.Package) (map[string]string, error) { if len(pkg.GoFiles) == 0 { return nil, nil diff --git a/gfutil/gfgo/testutil.go b/gfutil/gfgo/testutil.go index 73ed652..3f8bebc 100644 --- a/gfutil/gfgo/testutil.go +++ b/gfutil/gfgo/testutil.go @@ -2,7 +2,6 @@ package gfgo import ( "bytes" - "io/ioutil" "os" "os/exec" "path" @@ -81,7 +80,7 @@ func TestGenerate(t *testing.T, wrappers []goflow.GraphWrapper, filename string, } else if err != nil { require.NoError(err) } - err = ioutil.WriteFile(goFilename, buf.Bytes(), 0o600) + err = os.WriteFile(goFilename, buf.Bytes(), 0o600) require.NoError(err) mainFilename := path.Join("graph", "main.go") @@ -117,7 +116,7 @@ func TestGenerate(t *testing.T, wrappers []goflow.GraphWrapper, filename string, require.NoError(w.Flush()) require.NoError(err) - require.NoError(ioutil.WriteFile(mainFilename, buf.Bytes(), 0o600)) + require.NoError(os.WriteFile(mainFilename, buf.Bytes(), 0o600)) cmd := exec.Command("go", "run", "./graph") var out, errOut bytes.Buffer diff --git a/run.go b/run.go index d9d1c72..1eba8c7 100644 --- a/run.go +++ b/run.go @@ -2,7 +2,6 @@ package goflow import ( "fmt" - "io/ioutil" "os" "path" "strings" @@ -15,7 +14,7 @@ import ( // // It also logs the time taken since start, because why not. func WriteFile(content, filename string, start time.Time) error { - before, err := ioutil.ReadFile(filename) + before, err := os.ReadFile(filename) if err != nil && !os.IsNotExist(err) { return err } @@ -46,7 +45,7 @@ func WriteFile(content, filename string, start time.Time) error { } func FindGraphFileNames(dir string) ([]string, error) { - files, err := ioutil.ReadDir(dir) + files, err := os.ReadDir(dir) if err != nil { return nil, err } diff --git a/wrapper.go b/wrapper.go index d8eded4..a222f5a 100644 --- a/wrapper.go +++ b/wrapper.go @@ -8,6 +8,7 @@ package goflow // - NodeWrapper // - Linter // - Checker +// // goflow provides functions to use those simpler types as GraphWrappers. type GraphWrapper func(unmarshal func(interface{}) error, graph GraphRenderer) (GraphRenderer, error) diff --git a/wrappers/bind/graph/bind.go b/wrappers/bind/graph/bind.go index a74b10a..100786a 100644 --- a/wrappers/bind/graph/bind.go +++ b/wrappers/bind/graph/bind.go @@ -11,7 +11,6 @@ import ( ) /* - */ type Bind struct{} @@ -24,7 +23,6 @@ func newBind(id string) Bind { } /* - */ func (g *Bind) Run() { diff --git a/wrappers/constants/graph/constants.go b/wrappers/constants/graph/constants.go index 365085b..de6dc18 100644 --- a/wrappers/constants/graph/constants.go +++ b/wrappers/constants/graph/constants.go @@ -12,7 +12,6 @@ import ( ) /* - */ type Constants struct{} @@ -25,7 +24,6 @@ func newConstants(id string) Constants { } /* - */ func (g *Constants) Run() { diff --git a/wrappers/ctx/graph/ctx.go b/wrappers/ctx/graph/ctx.go index c70b1bf..582c187 100644 --- a/wrappers/ctx/graph/ctx.go +++ b/wrappers/ctx/graph/ctx.go @@ -12,7 +12,6 @@ import ( ) /* - */ type Ctx struct{} @@ -25,7 +24,6 @@ func newCtx(id string) Ctx { } /* - */ func (g *Ctx) Run(ctx context.Context) { diff --git a/wrappers/gonodes/graph/gonodes.go b/wrappers/gonodes/graph/gonodes.go index 6a0ca57..819c18b 100644 --- a/wrappers/gonodes/graph/gonodes.go +++ b/wrappers/gonodes/graph/gonodes.go @@ -10,7 +10,6 @@ import ( ) /* - */ type GoNodes struct{ debug bool } @@ -27,7 +26,6 @@ func newGoNodes(id string, debug bool) GoNodes { } /* - */ func (g *GoNodes) Run() { diff --git a/wrappers/ifs/graph/ifs.go b/wrappers/ifs/graph/ifs.go index 17301b5..2a6a2c6 100644 --- a/wrappers/ifs/graph/ifs.go +++ b/wrappers/ifs/graph/ifs.go @@ -11,7 +11,6 @@ import ( ) /* - */ type Ifs struct{} @@ -24,7 +23,6 @@ func newIfs(id string) Ifs { } /* - */ func (g *Ifs) Run() { diff --git a/wrappers/mockingjay/graph/mockingjay.go b/wrappers/mockingjay/graph/mockingjay.go index 084854c..bf09830 100644 --- a/wrappers/mockingjay/graph/mockingjay.go +++ b/wrappers/mockingjay/graph/mockingjay.go @@ -13,7 +13,6 @@ import ( ) /* - */ type Mockingjay struct{} @@ -26,7 +25,6 @@ func newMockingjay(id string) Mockingjay { } /* - */ func (g *Mockingjay) Run(ctx context.Context, a int, b int) (sum int) { @@ -42,6 +40,9 @@ func (g *Mockingjay) Run(ctx context.Context, a int, b int) (sum int) { // __output_sum_builder outputs var __output_sum_builder_sum int + // __print_values outputs + var __print_values_aggregated []interface{} + // add outputs var add_sum int @@ -49,6 +50,8 @@ func (g *Mockingjay) Run(ctx context.Context, a int, b int) (sum int) { var inputs_a int var inputs_b int + // print outputs + igniteNodeID := "ignite" doneNodeID := "done" @@ -106,6 +109,18 @@ func (g *Mockingjay) Run(ctx context.Context, a int, b int) (sum int) { }, alreadyDone: false, }, + "__print_values": { + deps: map[string]struct{}{ + "add": {}, + igniteNodeID: {}, + }, + run: func() { + __print_values_aggregated = append(__print_values_aggregated, "sum") + __print_values_aggregated = append(__print_values_aggregated, add_sum) + done <- "__print_values" + }, + alreadyDone: false, + }, "add": { deps: map[string]struct{}{ "__ctx": {}, @@ -159,6 +174,32 @@ func (g *Mockingjay) Run(ctx context.Context, a int, b int) (sum int) { }, alreadyDone: false, }, + "print": { + deps: map[string]struct{}{ + "__ctx": {}, + "__print_values": {}, + igniteNodeID: {}, + }, + run: func() { + + var _mock []interface{} + if _mocks, ok := ctx.Value(mockingjay.ContextKey).(map[string][]interface{}); ok && _mocks != nil { + m, ok := _mocks["print"] + if ok { + _mock = m + } + } + + if _mock != nil { + + } else { + nodes.PrinterCtx(__ctx_ctx, __print_values_aggregated) + } + + done <- "print" + }, + alreadyDone: false, + }, igniteNodeID: { deps: map[string]struct{}{}, run: func() { @@ -172,8 +213,10 @@ func (g *Mockingjay) Run(ctx context.Context, a int, b int) (sum int) { "__add_b": {}, "__ctx": {}, "__output_sum_builder": {}, + "__print_values": {}, "add": {}, "inputs": {}, + "print": {}, }, run: func() { done <- doneNodeID diff --git a/wrappers/mockingjay/mockingjay.go b/wrappers/mockingjay/mockingjay.go index 543d0ab..c2a3b04 100644 --- a/wrappers/mockingjay/mockingjay.go +++ b/wrappers/mockingjay/mockingjay.go @@ -31,8 +31,8 @@ func WithMock(ctx context.Context, nodeID string, values ...interface{}) context // // The WithMock helper function is provided to make it easier to mock node: // -// ctx := mockingjay.WithMock(ctx, "myNode", 42) -// graph.Run(ctx, ...) +// ctx := mockingjay.WithMock(ctx, "myNode", 42) +// graph.Run(ctx, ...) func Mock(_ func(interface{}) error, node goflow.NodeRenderer) (goflow.NodeRenderer, error) { return mocker{ NodeRenderer: ctx.Injector{ diff --git a/wrappers/mockingjay/mockingjay.yml b/wrappers/mockingjay/mockingjay.yml index e765583..b8ad588 100644 --- a/wrappers/mockingjay/mockingjay.yml +++ b/wrappers/mockingjay/mockingjay.yml @@ -11,5 +11,12 @@ nodes: a: inputs.a b: inputs.b + - id: print + type: nodes.PrinterCtx + bind: + values: + - '"sum"' + - add.sum + outputs: sum: add.sum diff --git a/wrappers/outputs/graph/outputs.go b/wrappers/outputs/graph/outputs.go index 48f620a..b825804 100644 --- a/wrappers/outputs/graph/outputs.go +++ b/wrappers/outputs/graph/outputs.go @@ -10,7 +10,6 @@ import ( ) /* - */ type Ouputs struct{} @@ -23,7 +22,6 @@ func newOuputs(id string) Ouputs { } /* - */ func (g *Ouputs) Run() (random_int int, random_ints []int) {