Remove units
This commit is contained in:
parent
6c8fd03a69
commit
5d41d0f85f
|
@ -1,26 +0,0 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"code.google.com/p/go.net/context"
|
||||
"github.com/localhots/yeast/units/aggregator"
|
||||
"github.com/localhots/yeast/units/logger"
|
||||
"github.com/localhots/yeast/units/power"
|
||||
"github.com/localhots/yeast/units/sleep"
|
||||
"github.com/localhots/yeast/units/uuid"
|
||||
)
|
||||
|
||||
type (
|
||||
UnitsDict map[string]func(context.Context) context.Context
|
||||
)
|
||||
|
||||
var (
|
||||
Units = UnitsDict{
|
||||
"aggregator": aggregator.Call,
|
||||
"logger": logger.Call,
|
||||
"power2": power.Power2,
|
||||
"power3": power.Power3,
|
||||
"power5": power.Power5,
|
||||
"sleep": sleep.Call,
|
||||
"uuid": uuid.Call,
|
||||
}
|
||||
)
|
|
@ -1,22 +0,0 @@
|
|||
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
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
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
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
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
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
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
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
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
|
||||
}
|
Loading…
Reference in New Issue