• Go では複雑でコストのかかる処理を隠すような機能は実装されない
  • []string[]interface{} に自動変換する良い方法や提供されている機能は無い
func foo([]interface{}) { /* do somthing */ }
func main() {
    var a[]string = []string{"hello", "world"}
    for(a)
}

毎回以下のように実装する必要がある

b = make([]interface{}, len(a), len(a))
for i := range a {
    b[i] = a[i]
}

参考

In Go, there is a general rule that syntax should not hide complex/costly operations.

Converting a string to an interface{} is done in O(1) time. Converting a []string to an interface{} is also done in O(1) time since a slice is still one value. However, converting a []string to an []interface{} is O(n) time because each element of the slice must be converted to an interface{}.

The one exception to this rule is converting strings. When converting a string to and from a []byte or a []rune, Go does O(n) work even though conversions are “syntax”.

There is no standard library function that will do this conversion for you. Your best option though is just to use the lines of code you gave in your question:

Goでは、複雑でコストのかかる操作を構文で隠してはいけないという一般的なルールがあります。

文字列をinterface{}に変換するのはO(1)時間です。文字列からインターフェース{}への変換もO(1)時間で行われます。しかし、[]stringから[]interface{}への変換は、sliceの各要素をinterface{}に変換する必要があるため、O(n)時間となります。

このルールの例外は文字列の変換です。文字列を[]byteや[]runeに変換するとき、変換は「構文」であるにもかかわらず、GoはO(n)個の作業をします。

この変換を行う標準ライブラリ関数はありません。ただし、最善のオプションは、質問で指定したコード行を使用することです。

Can I convert a []T to an []interface{}?

Not directly. It is disallowed by the language specification because the two types do not have the same representation in memory. It is necessary to copy the elements individually to the destination slice. This example converts a slice of int to a slice of interface{}:

[T]を[]interface{}に変換することはできますか?

直接はできません。この2つの型はメモリ上で同じ表現を持っていないため、言語仕様で禁止されています。変換先のスライスに個別に要素をコピーする必要があります.この例では,intのスライスをinterface{}のスライスに変換しています.

t := []int{1, 2, 3, 4}
s := make([]interface{}, len(t))
for i, v := range t {
    s[i] = v
}