main.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package main
  2. import (
  3. "bytes"
  4. "hexasoftware/lib/bench"
  5. _ "hexasoftware/lib/prettylog/global"
  6. "hexasoftware/lib/vnode"
  7. "log"
  8. )
  9. // Test 1 Sum 2 numbers
  10. // The goal:
  11. /*
  12. GetInput(1).Link(othervnode)
  13. */
  14. func sumFunc(a, b int) int {
  15. return a + b
  16. }
  17. func sumFuncV(args ...interface{}) interface{} {
  18. return args[0].(int) + args[1].(int)
  19. }
  20. func ret10() int {
  21. return 10
  22. }
  23. func main() {
  24. reverse := vnode.New(func(s string) string {
  25. var b bytes.Buffer
  26. for i := len(s) - 1; i >= 0; i-- {
  27. b.WriteByte(s[i])
  28. }
  29. return b.String()
  30. })
  31. reverse.Source("Hello from the other side")
  32. count := vnode.New(func(s string) int {
  33. return len(s)
  34. })
  35. count.Source("This is a big string")
  36. log.Println(reverse.Exec())
  37. sumNode1 := vnode.New(sumFunc, 2)
  38. var err error
  39. err = sumNode1.Source(count, ret10)
  40. log.Println("Error check", err)
  41. sumNode := vnode.New(sumFunc, 2)
  42. err = sumNode.Source(sumNode1, 2)
  43. log.Println("Error check", err)
  44. log.Println("Node:", sumNode.Exec())
  45. log.Printf("Func done")
  46. bench.Exec("main", func() interface{} {
  47. return sumNode.Exec()
  48. })
  49. }