I am trying to create a method that will append data already cached with non-cached data pulled from the db. Ideally a single method performing something similar as below would be ideal. So is there a way to append two interface{} refs that are both slices?
package main
import "fmt"
type foo struct {
Name string
}
func main() {
a := []*foo{
&foo{"bar"},
&foo{"boom"},
}
b := []*foo{
&foo{"blam"},
&foo{"pow"},
}
fmt.Println(add(a, b))
}
func add(a, b interface{}) interface{} {
return append([]interface{}{a}, ([]interface{}{b})...)
}
Results https://play.golang.org/p/9cWxPg6daq
[[0x1040a128 0x1040a130] [0x1040a140 0x1040a148]]
Desired Results
[0x1040a128 0x1040a130 0x1040a140 0x1040a148]
Update: Benchmarks
https://play.golang.org/p/9a8aZckQAF
C:\Users\chris\Go\src\bitbucket.org\chrisolsen\test>go test -bench=.
PASS
BenchmarkWithReflection-4 300000 4580 ns/op
BenchmarkNoReflection-4 300000 4194 ns/op
ok bitbucket.org/chrisolsen/test 2.911s