From c9f12472845805a59e88a654524ea46c82a4cb23 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Mon, 31 Aug 2020 21:10:32 +1000 Subject: [PATCH] Updated to use specialised update fuctions --- cmd/templates/vanilla/counter.go | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/cmd/templates/vanilla/counter.go b/cmd/templates/vanilla/counter.go index 2d2420db..ec93892c 100644 --- a/cmd/templates/vanilla/counter.go +++ b/cmd/templates/vanilla/counter.go @@ -24,24 +24,11 @@ func (c *Counter) RandomValue() { c.store.Set(rand.Intn(1000)) } -func (c *Counter) getInt(data interface{}) int { - - switch value := data.(type) { - case float64: - // All numbers sent by the frontend are float64 - // so we need to convert it back to an int - return int(value) - default: - return value.(int) - } -} - // Increment will increment the counter func (c *Counter) Increment() { - increment := func(data interface{}) interface{} { - currentValue := c.getInt(data) - return currentValue + 1 + increment := func(data int) int { + return data + 1 } // Update the store using the increment function @@ -51,9 +38,8 @@ func (c *Counter) Increment() { // Decrement will decrement the counter func (c *Counter) Decrement() { - decrement := func(data interface{}) interface{} { - currentValue := c.getInt(data) - return currentValue - 1 + decrement := func(data int) int { + return data - 1 } // Update the store using the decrement function c.store.Update(decrement)