dro80463
dro80463
2018-07-29 12:38
浏览 561
已采纳

Golang结构体中的字符串数组

Im using the following struct

type Str struct {
    Info    string
    Command string
}

And to fill data inside of it Im doing the following which works.

    return []Str{
        {"info from source",
            "install && run"},
    }

Now I need to change the command to array

type Str struct {
    Info    string
    Command []string
}

And provide each of the commands("install" and "run") in new entry in the array, how can I do that

when I try with

return []Str{
    {"info from source",string[]{
        {"install},  {"run"}},
}

I got erorr of missing type literal, any idea what Im doing wrong

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dsfb20227
    dsfb20227 2018-07-29 12:41
    已采纳

    The correct syntax is the following:

    return []Str{
        {"info from source", []string{"install", "run"}},
    }
    
    点赞 评论

相关推荐