Initial commit
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package aggregator
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"code.google.com/p/go.net/context"
|
||||
"github.com/localhots/yeast/tools"
|
||||
"github.com/localhots/yeast/units/power"
|
||||
)
|
||||
|
||||
func Call(ctx context.Context) context.Context {
|
||||
results := []string{}
|
||||
|
||||
tools.SyncronizeParallelChain(ctx, func(ctx context.Context) {
|
||||
r := ctx.Value("power_result").(power.PowerResult)
|
||||
results = append(results, fmt.Sprintf("%d ^ %d = %d", r.Num, r.Power, r.Result))
|
||||
})
|
||||
|
||||
ctx = context.WithValue(ctx, "power_results", results)
|
||||
|
||||
return ctx
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package input
|
||||
|
||||
import (
|
||||
"flag"
|
||||
|
||||
"code.google.com/p/go.net/context"
|
||||
)
|
||||
|
||||
func FromFlag(ctx context.Context) context.Context {
|
||||
var num int
|
||||
flag.IntVar(&num, "num", 0, "Pass this number")
|
||||
flag.Parse()
|
||||
|
||||
ctx = context.WithValue(ctx, "num", num)
|
||||
|
||||
return ctx
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"code.google.com/p/go.net/context"
|
||||
)
|
||||
|
||||
func Call(ctx context.Context) context.Context {
|
||||
results := ctx.Value("power_results").([]string)
|
||||
id := ctx.Value("id").(string)
|
||||
|
||||
fmt.Println("Calculation result", id)
|
||||
fmt.Println("Power results are:")
|
||||
for _, r := range results {
|
||||
fmt.Println(r)
|
||||
}
|
||||
|
||||
return ctx
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package power
|
||||
|
||||
import (
|
||||
"code.google.com/p/go.net/context"
|
||||
)
|
||||
|
||||
type (
|
||||
PowerResult struct {
|
||||
Num int
|
||||
Power int
|
||||
Result int
|
||||
}
|
||||
)
|
||||
|
||||
func Power2(ctx context.Context) context.Context {
|
||||
v := ctx.Value("num").(int)
|
||||
res := PowerResult{Num: v, Power: 2, Result: v * v}
|
||||
ctx = context.WithValue(ctx, "power_result", res)
|
||||
|
||||
return ctx
|
||||
}
|
||||
|
||||
func Power3(ctx context.Context) context.Context {
|
||||
v := ctx.Value("num").(int)
|
||||
res := PowerResult{Num: v, Power: 3, Result: v * v * v}
|
||||
ctx = context.WithValue(ctx, "power_result", res)
|
||||
|
||||
return ctx
|
||||
}
|
||||
|
||||
func Power5(ctx context.Context) context.Context {
|
||||
v := ctx.Value("num").(int)
|
||||
res := PowerResult{Num: v, Power: 5, Result: v * v * v * v * v}
|
||||
ctx = context.WithValue(ctx, "power_result", res)
|
||||
|
||||
return ctx
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package sleep
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"code.google.com/p/go.net/context"
|
||||
)
|
||||
|
||||
func Call(ctx context.Context) context.Context {
|
||||
fmt.Println("Going into sleep")
|
||||
time.Sleep(5 * time.Second)
|
||||
fmt.Println("Woke up")
|
||||
return ctx
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package uuid
|
||||
|
||||
import (
|
||||
"code.google.com/p/go-uuid/uuid"
|
||||
"code.google.com/p/go.net/context"
|
||||
)
|
||||
|
||||
func Call(ctx context.Context) context.Context {
|
||||
ctx = context.WithValue(ctx, "id", uuid.New())
|
||||
|
||||
return ctx
|
||||
}
|
||||
Reference in New Issue
Block a user