Here is an example of variable:
names := []interface{}{"first", "second"}
How can it be initialized dynamically, from an array of strings?
strs := []string{"first", "second"}
names := make([]interface{}, len(strs))
for i, s := range strs {
names[i] = s
}
Would be the simplest
another way:
strs := []string{"first", "second"}
var names []string
names = append(names, strs...)
If there are only two strings that are to be added dynamically, this works too:
var names []interface{}
names = append(names, "first")
names = append(names, "second")
Or this:
var names []interface{}
names = append(names, "first", "second")