|
@@ -1,14 +1,13 @@
|
|
|
package main
|
|
|
|
|
|
import (
|
|
|
- "errors"
|
|
|
"flow"
|
|
|
"flow/registry"
|
|
|
"flowserver"
|
|
|
+ "flowserver/cmd/flowserver/floatops"
|
|
|
"fmt"
|
|
|
+ "io"
|
|
|
"log"
|
|
|
- "math/rand"
|
|
|
- "strings"
|
|
|
"time"
|
|
|
|
|
|
"github.com/gohxs/prettylog"
|
|
@@ -16,46 +15,19 @@ import (
|
|
|
|
|
|
func main() {
|
|
|
prettylog.Global()
|
|
|
-
|
|
|
log.Println("Running version:", flowserver.Version)
|
|
|
|
|
|
- registry.Batch{
|
|
|
- flow.Register("delay.cat", delayCat),
|
|
|
- flow.Register("delay.reverse", delayReverse),
|
|
|
- flow.Register("delay.split", delaySplit),
|
|
|
- flow.Register("delay.join", delayJoin),
|
|
|
- flow.Register("addduration", duration),
|
|
|
- }.Categories("string", "test").
|
|
|
- Extra("style", map[string]string{
|
|
|
- "color": "#a55",
|
|
|
- })
|
|
|
+ floatops.Register(registry.Global)
|
|
|
|
|
|
- registry.Batch{
|
|
|
- flow.Register("longduration", duration(10*time.Second)),
|
|
|
- flow.Register("mediumduration", duration(5*time.Second)),
|
|
|
- flow.Register("randomduration", randduration(10*time.Second)),
|
|
|
- }.Categories("time simulation")
|
|
|
+ registry.Add(customStruct, setName, setURL).Categories("test-struct")
|
|
|
|
|
|
- registry.Batch{
|
|
|
- flow.Register("multiplex4", multiplex4),
|
|
|
- flow.Register("multiplex6", multiplex6),
|
|
|
- flow.Register("error", func(s string) (string, error) {
|
|
|
- time.Sleep(4 * time.Second)
|
|
|
- return "", errors.New("Some error")
|
|
|
- }),
|
|
|
- }.Categories("test").
|
|
|
- Extra("style", map[string]string{
|
|
|
- "color": "#959",
|
|
|
- })
|
|
|
+ registry.Batch{registry.Register("stream", stream)}.Categories("streamer")
|
|
|
|
|
|
registry.Batch{
|
|
|
- flow.Register("str.cat", strCat),
|
|
|
- flow.Register("str.reverse", strReverse),
|
|
|
- flow.Register("str.split", strings.Split),
|
|
|
- flow.Register("str.join", strings.Join),
|
|
|
- }.Categories("string").
|
|
|
+ registry.Register("wait", wait),
|
|
|
+ }.Categories("time-test").
|
|
|
Extra("style", map[string]string{
|
|
|
- "color": "#aa5",
|
|
|
+ "color": "#8a5",
|
|
|
})
|
|
|
|
|
|
addr := ":2015"
|
|
@@ -65,65 +37,30 @@ func main() {
|
|
|
f.ListenAndServe(addr)
|
|
|
}
|
|
|
|
|
|
-func multiplex4(a1, a2, a3, a4 string) string {
|
|
|
- return strings.Join([]string{a1, a2, a3, a4}, " ")
|
|
|
-}
|
|
|
-func multiplex6(a1, a2, a3, a4, a5, a6 string) string {
|
|
|
- return strings.Join([]string{a1, a2, a3, a4, a5, a6}, " ")
|
|
|
+func wait(data flow.Data, n int) flow.Data {
|
|
|
+ time.Sleep(time.Duration(n) * time.Second) // Simulate
|
|
|
+ return data
|
|
|
}
|
|
|
|
|
|
-/* Sample funcs */
|
|
|
-func strCat(a1, a2 string) string {
|
|
|
- return a1 + " " + a2
|
|
|
+func stream(w io.Writer, val interface{}) interface{} {
|
|
|
+ fmt.Fprint(w, val)
|
|
|
+ return val
|
|
|
}
|
|
|
|
|
|
-func strReverse(s string) string {
|
|
|
- n := len(s)
|
|
|
- runes := make([]rune, n)
|
|
|
- for _, r := range s {
|
|
|
- n--
|
|
|
- runes[n] = r
|
|
|
- }
|
|
|
- return string(runes[n:])
|
|
|
+// CustomStruct testing custom struct passing
|
|
|
+type CustomStruct struct {
|
|
|
+ Name string
|
|
|
+ Url string
|
|
|
}
|
|
|
|
|
|
-func delayCat(a1, a2 string) string {
|
|
|
- time.Sleep(time.Duration(2+rand.Intn(10)) * time.Second) // Simulate
|
|
|
- return strCat(a1, a2)
|
|
|
+func customStruct() CustomStruct {
|
|
|
+ return CustomStruct{}
|
|
|
}
|
|
|
-
|
|
|
-func delayReverse(s string) string {
|
|
|
- time.Sleep(time.Duration(2+rand.Intn(10)) * time.Second) // Simulate
|
|
|
- return strReverse(s)
|
|
|
-
|
|
|
-}
|
|
|
-func delaySplit(s, sep string) []string {
|
|
|
- time.Sleep(time.Duration(2+rand.Intn(10)) * time.Second) // Simulate
|
|
|
- return strings.Split(s, sep)
|
|
|
-}
|
|
|
-func delayJoin(s []string, join string) string {
|
|
|
- time.Sleep(time.Duration(2+rand.Intn(10)) * time.Second) // Simulate
|
|
|
- return strings.Join(s, join)
|
|
|
-}
|
|
|
-
|
|
|
-func longduration() string {
|
|
|
- mark := time.Now()
|
|
|
- time.Sleep(25 * time.Second) // Simulate
|
|
|
- now := time.Now()
|
|
|
-
|
|
|
- return " took: " + fmt.Sprint(now.Sub(mark))
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-func duration(n time.Duration) func() string {
|
|
|
- return func() string {
|
|
|
- time.Sleep(n)
|
|
|
- return fmt.Sprint("I waited:", n)
|
|
|
- }
|
|
|
+func setName(a CustomStruct, name string) CustomStruct {
|
|
|
+ a.Name = name
|
|
|
+ return a
|
|
|
}
|
|
|
-func randduration(n time.Duration) func() string {
|
|
|
- return func() string {
|
|
|
- time.Sleep(time.Duration(2 + rand.Intn(int(n)))) // Simulate
|
|
|
- return fmt.Sprint("I waited:", n)
|
|
|
- }
|
|
|
+func setURL(a CustomStruct, url string) CustomStruct {
|
|
|
+ a.Url = url
|
|
|
+ return a
|
|
|
}
|