l'initialisation d'une structure contenant une tranche de structs dans golang

J'ai un struct que je veux initialiser avec une tranche de structs dans golang, mais je suis en train de voir si il est plus efficace en version d'ajout de chaque nouveau généré struct pour la tranche:

package main

import (
    "fmt"
    "math/rand"
)

type LuckyNumber struct {
    number int
}

type Person struct {
    lucky_numbers []LuckyNumber
}

func main() {
    count_of_lucky_nums := 10
    //START OF SECTION I WANT TO OPTIMIZE
    var tmp []LuckyNumber
    for i := 0; i < count_of_lucky_nums; i++ {
        tmp = append(tmp, LuckyNumber{rand.Intn(100)})
    }
    a := Person{tmp}
    //END OF SECTION I WANT TO OPTIMIZE
    fmt.Println(a)
}
InformationsquelleAutor mgoldwasser | 2017-03-03