Skip to content

Commit

Permalink
doc: working on README
Browse files Browse the repository at this point in the history
  • Loading branch information
Iván Corrales Solera committed Dec 15, 2018
1 parent fef1a3e commit 5f7f063
Showing 1 changed file with 42 additions and 44 deletions.
86 changes: 42 additions & 44 deletions internal/set/dispatcher.go
Original file line number Diff line number Diff line change
@@ -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
}

Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit 5f7f063

Please sign in to comment.