It's not immediately obvious what you're trying to do, but here's one
possible solution: https://play.golang.org/p/wrrDlvDISq

On Tue, Aug 22, 2017 at 8:38 AM, Tong Sun <suntong...@gmail.com> wrote:
> Hi,
>
> How to initialize a go struct like the following?
>
>  type Server struct {
>  Name    string
>  ID      int32
>  Enabled bool
>  }
>
>  s := struct {
>     Servers     []Server{
>       {
>         Name:    "Arslan",
>         ID:      123456,
>         Enabled: true,
>       },
>       {
>         Name:    "Arslan",
>         ID:      123456,
>         Enabled: true,
>       },
>     }
>   }
>
>
>
> That didn't work so I tried to introduce a new type to capture it:
>
>  type Server struct {
>  Name    string
>  ID      int32
>  Enabled bool
>  }
>  type Servers struct {
>  servers []Server
>  }
>
>
>  s := &Servers{servers: []Server{
>       {
>         Name:    "Arslan",
>         ID:      123456,
>         Enabled: true,
>       },
>       {
>         Name:    "Arslan",
>         ID:      123456,
>         Enabled: true,
>       },
>     }
>
>
> but that failed also.
>
> What's the correct way?
> Please help. Thx.
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to