From 5f7f06347feb7697b420b5cc70bd76a67cef5bd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Corrales=20Solera?= Date: Sat, 15 Dec 2018 12:18:37 +0100 Subject: [PATCH] doc: working on README --- internal/set/dispatcher.go | 86 +++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 44 deletions(-) diff --git a/internal/set/dispatcher.go b/internal/set/dispatcher.go index 3bc699b..766db56 100644 --- a/internal/set/dispatcher.go +++ b/internal/set/dispatcher.go @@ -1,47 +1,45 @@ - package set import "reflect" - -type dispatchFunction func(items reflect.Value,index int, item interface{}) interface{} +type dispatchFunction func(items reflect.Value, index int, item interface{}) interface{} var dispatcher = map[string]dispatchFunction{ - "string": setString, + "string": setString, "*string": setPtrString, - "bool": setBool, - "*bool": setPtrBool, - "int": setInt, - "*int": setPtrInt, - "int8": setInt8, - "*int8": setPtrInt8, - "int16": setInt16, - "*int16": setPtrInt16, - "int32": setInt32, - "*int32": setPtrInt32, - "int64": setInt64, - "*int64": setPtrInt64, - "uint": setUint, - "*uint": setPtrUint, - "uint8": setUint8, - "*uint8": setPtrUint8, - "uint16": setUint16, + "bool": setBool, + "*bool": setPtrBool, + "int": setInt, + "*int": setPtrInt, + "int8": setInt8, + "*int8": setPtrInt8, + "int16": setInt16, + "*int16": setPtrInt16, + "int32": setInt32, + "*int32": setPtrInt32, + "int64": setInt64, + "*int64": setPtrInt64, + "uint": setUint, + "*uint": setPtrUint, + "uint8": setUint8, + "*uint8": setPtrUint8, + "uint16": setUint16, "*uint16": setPtrUint16, - "uint32": setUint32, + "uint32": setUint32, "*uint32": setPtrUint32, - "uint64": setUint64, + "uint64": setUint64, "*uint64": setPtrUint64, "float32": setFloat32, - "*float32": setPtrFloat32, + "*float32": setPtrFloat32, "float64": setFloat64, - "*float64": setPtrFloat64, + "*float64": setPtrFloat64, } -func dispatch(items reflect.Value, itemValue interface{}, info *setInfo) (bool,interface{}) { - input:=(*info.itemType).String() - if fnVal,ok:=dispatcher[input];ok{ - return true, fnVal(items,info.index,itemValue) - } +func dispatch(items reflect.Value, itemValue interface{}, info *setInfo) (bool, interface{}) { + input := (*info.itemType).String() + if fnVal, ok := dispatcher[input]; ok { + return true, fnVal(items, info.index, itemValue) + } return false, nil } @@ -50,7 +48,7 @@ func setString(itemsValue reflect.Value, index int, itemValue interface{}) inter item := itemValue.(string) n := len(input) output := make([]string, n) - copy(output,input) + copy(output, input) output[index] = item return output } @@ -70,7 +68,7 @@ func setBool(itemsValue reflect.Value, index int, itemValue interface{}) interfa item := itemValue.(bool) n := len(input) output := make([]bool, n) - copy(output,input) + copy(output, input) output[index] = item return output } @@ -90,7 +88,7 @@ func setInt(itemsValue reflect.Value, index int, itemValue interface{}) interfac item := itemValue.(int) n := len(input) output := make([]int, n) - copy(output,input) + copy(output, input) output[index] = item return output } @@ -110,7 +108,7 @@ func setInt8(itemsValue reflect.Value, index int, itemValue interface{}) interfa item := itemValue.(int8) n := len(input) output := make([]int8, n) - copy(output,input) + copy(output, input) output[index] = item return output } @@ -130,7 +128,7 @@ func setInt16(itemsValue reflect.Value, index int, itemValue interface{}) interf item := itemValue.(int16) n := len(input) output := make([]int16, n) - copy(output,input) + copy(output, input) output[index] = item return output } @@ -150,7 +148,7 @@ func setInt32(itemsValue reflect.Value, index int, itemValue interface{}) interf item := itemValue.(int32) n := len(input) output := make([]int32, n) - copy(output,input) + copy(output, input) output[index] = item return output } @@ -170,7 +168,7 @@ func setInt64(itemsValue reflect.Value, index int, itemValue interface{}) interf item := itemValue.(int64) n := len(input) output := make([]int64, n) - copy(output,input) + copy(output, input) output[index] = item return output } @@ -190,7 +188,7 @@ func setUint(itemsValue reflect.Value, index int, itemValue interface{}) interfa item := itemValue.(uint) n := len(input) output := make([]uint, n) - copy(output,input) + copy(output, input) output[index] = item return output } @@ -210,7 +208,7 @@ func setUint8(itemsValue reflect.Value, index int, itemValue interface{}) interf item := itemValue.(uint8) n := len(input) output := make([]uint8, n) - copy(output,input) + copy(output, input) output[index] = item return output } @@ -230,7 +228,7 @@ func setUint16(itemsValue reflect.Value, index int, itemValue interface{}) inter item := itemValue.(uint16) n := len(input) output := make([]uint16, n) - copy(output,input) + copy(output, input) output[index] = item return output } @@ -250,7 +248,7 @@ func setUint32(itemsValue reflect.Value, index int, itemValue interface{}) inter item := itemValue.(uint32) n := len(input) output := make([]uint32, n) - copy(output,input) + copy(output, input) output[index] = item return output } @@ -270,7 +268,7 @@ func setUint64(itemsValue reflect.Value, index int, itemValue interface{}) inter item := itemValue.(uint64) n := len(input) output := make([]uint64, n) - copy(output,input) + copy(output, input) output[index] = item return output } @@ -290,7 +288,7 @@ func setFloat32(itemsValue reflect.Value, index int, itemValue interface{}) inte item := itemValue.(float32) n := len(input) output := make([]float32, n) - copy(output,input) + copy(output, input) output[index] = item return output } @@ -310,7 +308,7 @@ func setFloat64(itemsValue reflect.Value, index int, itemValue interface{}) inte item := itemValue.(float64) n := len(input) output := make([]float64, n) - copy(output,input) + copy(output, input) output[index] = item return output }