diff --git a/examples/flogo/creditcard/imports.go b/examples/flogo/creditcard/imports.go new file mode 100644 index 0000000..89913aa --- /dev/null +++ b/examples/flogo/creditcard/imports.go @@ -0,0 +1,6 @@ +package main + +import ( + _ "github.com/project-flogo/rules/ruleaction" + _ "github.com/project-flogo/contrib/trigger/rest" +) diff --git a/examples/flogo/creditcard/main.go b/examples/flogo/creditcard/main.go index 132d1a2..68b9b88 100644 --- a/examples/flogo/creditcard/main.go +++ b/examples/flogo/creditcard/main.go @@ -9,41 +9,43 @@ import ( _ "github.com/project-flogo/core/data/expression/script" "github.com/project-flogo/core/engine" - "github.com/project-flogo/core/support/log" - - _ "github.com/project-flogo/contrib/trigger/rest" - _ "github.com/project-flogo/rules/ruleaction" ) var ( cpuProfile = flag.String("cpuprofile", "", "Writes CPU profile to the specified file") memProfile = flag.String("memprofile", "", "Writes memory profile to the specified file") cfgJson string + cfgEngine string cfgCompressed bool ) func main() { + cpuProfiling := false + flag.Parse() if *cpuProfile != "" { f, err := os.Create(*cpuProfile) if err != nil { - fmt.Println(fmt.Sprintf("Failed to create CPU profiling file due to error - %s", err.Error())) + fmt.Fprintf(os.Stderr, "Failed to create CPU profiling file: %v\n", err) + os.Exit(1) + } + if err = pprof.StartCPUProfile(f); err != nil { + fmt.Fprintf(os.Stderr, "Failed to start CPU profiling: %v\n", err) os.Exit(1) } - pprof.StartCPUProfile(f) - defer pprof.StopCPUProfile() + cpuProfiling = true } cfg, err := engine.LoadAppConfig(cfgJson, cfgCompressed) if err != nil { - log.RootLogger().Errorf("Failed to create engine: %s", err.Error()) + fmt.Fprintf(os.Stderr, "Failed to create engine: %v\n", err) os.Exit(1) } - e, err := engine.New(cfg) + e, err := engine.New(cfg, engine.ConfigOption(cfgEngine, cfgCompressed)) if err != nil { - log.RootLogger().Errorf("Failed to create engine: %s", err.Error()) + fmt.Fprintf(os.Stderr, "Failed to create engine: %v\n", err) os.Exit(1) } @@ -52,17 +54,21 @@ func main() { if *memProfile != "" { f, err := os.Create(*memProfile) if err != nil { - fmt.Println(fmt.Sprintf("Failed to create memory profiling file due to error - %s", err.Error())) + fmt.Fprintf(os.Stderr, "Failed to create memory profiling file: %v\n", err) os.Exit(1) } runtime.GC() // get up-to-date statistics if err := pprof.WriteHeapProfile(f); err != nil { - fmt.Println(fmt.Sprintf("Failed to write memory profiling data to file due to error - %s", err.Error())) + fmt.Fprintf(os.Stderr, "Failed to write memory profiling data: %v", err) os.Exit(1) } - f.Close() + _ = f.Close() + } + + if cpuProfiling { + pprof.StopCPUProfile() } os.Exit(code) -} +} \ No newline at end of file diff --git a/examples/flogo/simple-kafka/imports.go b/examples/flogo/simple-kafka/imports.go new file mode 100644 index 0000000..701b350 --- /dev/null +++ b/examples/flogo/simple-kafka/imports.go @@ -0,0 +1,6 @@ +package main + +import ( + _ "github.com/project-flogo/contrib/trigger/kafka" + _ "github.com/project-flogo/rules/ruleaction" +) diff --git a/examples/flogo/simple-kafka/main.go b/examples/flogo/simple-kafka/main.go index b4de78f..68b9b88 100644 --- a/examples/flogo/simple-kafka/main.go +++ b/examples/flogo/simple-kafka/main.go @@ -9,41 +9,43 @@ import ( _ "github.com/project-flogo/core/data/expression/script" "github.com/project-flogo/core/engine" - "github.com/project-flogo/core/support/log" - - _ "github.com/project-flogo/contrib/trigger/kafka" - _ "github.com/project-flogo/rules/ruleaction" ) var ( cpuProfile = flag.String("cpuprofile", "", "Writes CPU profile to the specified file") memProfile = flag.String("memprofile", "", "Writes memory profile to the specified file") - cfgJSON string + cfgJson string + cfgEngine string cfgCompressed bool ) func main() { + cpuProfiling := false + flag.Parse() if *cpuProfile != "" { f, err := os.Create(*cpuProfile) if err != nil { - fmt.Println(fmt.Sprintf("Failed to create CPU profiling file due to error - %s", err.Error())) + fmt.Fprintf(os.Stderr, "Failed to create CPU profiling file: %v\n", err) + os.Exit(1) + } + if err = pprof.StartCPUProfile(f); err != nil { + fmt.Fprintf(os.Stderr, "Failed to start CPU profiling: %v\n", err) os.Exit(1) } - pprof.StartCPUProfile(f) - defer pprof.StopCPUProfile() + cpuProfiling = true } - cfg, err := engine.LoadAppConfig(cfgJSON, cfgCompressed) + cfg, err := engine.LoadAppConfig(cfgJson, cfgCompressed) if err != nil { - log.RootLogger().Errorf("Failed to create engine: %s", err.Error()) + fmt.Fprintf(os.Stderr, "Failed to create engine: %v\n", err) os.Exit(1) } - e, err := engine.New(cfg) + e, err := engine.New(cfg, engine.ConfigOption(cfgEngine, cfgCompressed)) if err != nil { - log.RootLogger().Errorf("Failed to create engine: %s", err.Error()) + fmt.Fprintf(os.Stderr, "Failed to create engine: %v\n", err) os.Exit(1) } @@ -52,17 +54,21 @@ func main() { if *memProfile != "" { f, err := os.Create(*memProfile) if err != nil { - fmt.Println(fmt.Sprintf("Failed to create memory profiling file due to error - %s", err.Error())) + fmt.Fprintf(os.Stderr, "Failed to create memory profiling file: %v\n", err) os.Exit(1) } runtime.GC() // get up-to-date statistics if err := pprof.WriteHeapProfile(f); err != nil { - fmt.Println(fmt.Sprintf("Failed to write memory profiling data to file due to error - %s", err.Error())) + fmt.Fprintf(os.Stderr, "Failed to write memory profiling data: %v", err) os.Exit(1) } - f.Close() + _ = f.Close() + } + + if cpuProfiling { + pprof.StopCPUProfile() } os.Exit(code) -} +} \ No newline at end of file diff --git a/examples/flogo/simple/imports.go b/examples/flogo/simple/imports.go new file mode 100644 index 0000000..de2804e --- /dev/null +++ b/examples/flogo/simple/imports.go @@ -0,0 +1,6 @@ +package main + +import ( + _ "github.com/project-flogo/contrib/trigger/rest" + _ "github.com/project-flogo/rules/ruleaction" +) diff --git a/examples/flogo/simple/main.go b/examples/flogo/simple/main.go index b1f6c5b..68b9b88 100644 --- a/examples/flogo/simple/main.go +++ b/examples/flogo/simple/main.go @@ -9,42 +9,43 @@ import ( _ "github.com/project-flogo/core/data/expression/script" "github.com/project-flogo/core/engine" - "github.com/project-flogo/core/support/log" - - _ "github.com/project-flogo/contrib/trigger/rest" - _ "github.com/project-flogo/rules/ruleaction" - ) var ( - cpuProfile = flag.String("cpuprofile", "", "Writes CPU profile to the specified file") - memProfile = flag.String("memprofile", "", "Writes memory profile to the specified file") - cfgJson string + cpuProfile = flag.String("cpuprofile", "", "Writes CPU profile to the specified file") + memProfile = flag.String("memprofile", "", "Writes memory profile to the specified file") + cfgJson string + cfgEngine string cfgCompressed bool ) func main() { + cpuProfiling := false + flag.Parse() if *cpuProfile != "" { f, err := os.Create(*cpuProfile) if err != nil { - fmt.Println(fmt.Sprintf("Failed to create CPU profiling file due to error - %s", err.Error())) + fmt.Fprintf(os.Stderr, "Failed to create CPU profiling file: %v\n", err) os.Exit(1) } - pprof.StartCPUProfile(f) - defer pprof.StopCPUProfile() + if err = pprof.StartCPUProfile(f); err != nil { + fmt.Fprintf(os.Stderr, "Failed to start CPU profiling: %v\n", err) + os.Exit(1) + } + cpuProfiling = true } cfg, err := engine.LoadAppConfig(cfgJson, cfgCompressed) if err != nil { - log.RootLogger().Errorf("Failed to create engine: %s", err.Error()) + fmt.Fprintf(os.Stderr, "Failed to create engine: %v\n", err) os.Exit(1) } - e, err := engine.New(cfg) + e, err := engine.New(cfg, engine.ConfigOption(cfgEngine, cfgCompressed)) if err != nil { - log.RootLogger().Errorf("Failed to create engine: %s", err.Error()) + fmt.Fprintf(os.Stderr, "Failed to create engine: %v\n", err) os.Exit(1) } @@ -53,17 +54,21 @@ func main() { if *memProfile != "" { f, err := os.Create(*memProfile) if err != nil { - fmt.Println(fmt.Sprintf("Failed to create memory profiling file due to error - %s", err.Error())) + fmt.Fprintf(os.Stderr, "Failed to create memory profiling file: %v\n", err) os.Exit(1) } runtime.GC() // get up-to-date statistics if err := pprof.WriteHeapProfile(f); err != nil { - fmt.Println(fmt.Sprintf("Failed to write memory profiling data to file due to error - %s", err.Error())) + fmt.Fprintf(os.Stderr, "Failed to write memory profiling data: %v", err) os.Exit(1) } - f.Close() + _ = f.Close() + } + + if cpuProfiling { + pprof.StopCPUProfile() } os.Exit(code) -} +} \ No newline at end of file diff --git a/examples/flogo/trackntrace/imports.go b/examples/flogo/trackntrace/imports.go new file mode 100644 index 0000000..de2804e --- /dev/null +++ b/examples/flogo/trackntrace/imports.go @@ -0,0 +1,6 @@ +package main + +import ( + _ "github.com/project-flogo/contrib/trigger/rest" + _ "github.com/project-flogo/rules/ruleaction" +) diff --git a/examples/flogo/trackntrace/main.go b/examples/flogo/trackntrace/main.go index b1f6c5b..68b9b88 100644 --- a/examples/flogo/trackntrace/main.go +++ b/examples/flogo/trackntrace/main.go @@ -9,42 +9,43 @@ import ( _ "github.com/project-flogo/core/data/expression/script" "github.com/project-flogo/core/engine" - "github.com/project-flogo/core/support/log" - - _ "github.com/project-flogo/contrib/trigger/rest" - _ "github.com/project-flogo/rules/ruleaction" - ) var ( - cpuProfile = flag.String("cpuprofile", "", "Writes CPU profile to the specified file") - memProfile = flag.String("memprofile", "", "Writes memory profile to the specified file") - cfgJson string + cpuProfile = flag.String("cpuprofile", "", "Writes CPU profile to the specified file") + memProfile = flag.String("memprofile", "", "Writes memory profile to the specified file") + cfgJson string + cfgEngine string cfgCompressed bool ) func main() { + cpuProfiling := false + flag.Parse() if *cpuProfile != "" { f, err := os.Create(*cpuProfile) if err != nil { - fmt.Println(fmt.Sprintf("Failed to create CPU profiling file due to error - %s", err.Error())) + fmt.Fprintf(os.Stderr, "Failed to create CPU profiling file: %v\n", err) os.Exit(1) } - pprof.StartCPUProfile(f) - defer pprof.StopCPUProfile() + if err = pprof.StartCPUProfile(f); err != nil { + fmt.Fprintf(os.Stderr, "Failed to start CPU profiling: %v\n", err) + os.Exit(1) + } + cpuProfiling = true } cfg, err := engine.LoadAppConfig(cfgJson, cfgCompressed) if err != nil { - log.RootLogger().Errorf("Failed to create engine: %s", err.Error()) + fmt.Fprintf(os.Stderr, "Failed to create engine: %v\n", err) os.Exit(1) } - e, err := engine.New(cfg) + e, err := engine.New(cfg, engine.ConfigOption(cfgEngine, cfgCompressed)) if err != nil { - log.RootLogger().Errorf("Failed to create engine: %s", err.Error()) + fmt.Fprintf(os.Stderr, "Failed to create engine: %v\n", err) os.Exit(1) } @@ -53,17 +54,21 @@ func main() { if *memProfile != "" { f, err := os.Create(*memProfile) if err != nil { - fmt.Println(fmt.Sprintf("Failed to create memory profiling file due to error - %s", err.Error())) + fmt.Fprintf(os.Stderr, "Failed to create memory profiling file: %v\n", err) os.Exit(1) } runtime.GC() // get up-to-date statistics if err := pprof.WriteHeapProfile(f); err != nil { - fmt.Println(fmt.Sprintf("Failed to write memory profiling data to file due to error - %s", err.Error())) + fmt.Fprintf(os.Stderr, "Failed to write memory profiling data: %v", err) os.Exit(1) } - f.Close() + _ = f.Close() + } + + if cpuProfiling { + pprof.StopCPUProfile() } os.Exit(code) -} +} \ No newline at end of file