diff --git a/core/units.go b/core/units.go deleted file mode 100644 index 404f6d2..0000000 --- a/core/units.go +++ /dev/null @@ -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, - } -) diff --git a/units/aggregator/aggregator.go b/units/aggregator/aggregator.go deleted file mode 100644 index 6b7177f..0000000 --- a/units/aggregator/aggregator.go +++ /dev/null @@ -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 -} diff --git a/units/logger/logger.go b/units/logger/logger.go deleted file mode 100644 index cc03442..0000000 --- a/units/logger/logger.go +++ /dev/null @@ -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 -} diff --git a/units/power/power.go b/units/power/power.go deleted file mode 100644 index 6b7075c..0000000 --- a/units/power/power.go +++ /dev/null @@ -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 -} diff --git a/units/sleep/sleep.go b/units/sleep/sleep.go deleted file mode 100644 index 3a70f96..0000000 --- a/units/sleep/sleep.go +++ /dev/null @@ -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 -} diff --git a/units/uuid/uuid.go b/units/uuid/uuid.go deleted file mode 100644 index 665d6b3..0000000 --- a/units/uuid/uuid.go +++ /dev/null @@ -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 -}