Golang - can I have a struct with slice member?

go

Solution

you can have a slice or you can have a fixed size array defined at runtime

package main

import "fmt"

func main() {
    mystruct := struct {
        array [3]int
        slice [] int
    }{
        [...]int{1, 2, 3},
        []int{1, 2, 3, 4, 5},
    }
    fmt.Println(mystruct)
}

Problem

Is it possible to have a slice as a member of struct in Go? If so, how do I do it?

Original source