FAQ
Hi,

sorry if this is a dumb question but I am very new to Go and not even that
sure how to phrase the question.

I am working on adding features to a Terraform provider and the existing
code defines the following:

createvapp := &types.InstantiateVAppTemplateParams{
Ovf: "http://schemas.dmtf.org/ovf/envelope/1",
Xmlns: "http://www.vmware.com/vcloud/v1.5",
Name: d.Get("name").(string),
InstantiationParams: &types.InstantiationParams{
NetworkConfigSection: &types.NetworkConfigSection{
Info: "Configuration parameters for logical networks",
                                 NetworkConfig:
&types.VAppNetworkConfiguration{
NetworkName: d.Get("network_name").(string),
Configuration: &types.NetworkConfiguration{
ParentNetwork: &types.Reference{
HREF: networkHref,
},
FenceMode: "bridged",
},
},
Source: &types.Reference{
HREF: vapptemplate.VAppTemplate.HREF,
},
}



I need to refactor this so that I can pass in a variable number of
"NetworkConfig" types from a stored map.

In Ruby I would do something like:

NetworkConfigSection: &types.NetworkConfigSection{
Info: "Configuration parameters for logical networks",
         for _,network := range resolved_net_info {
           detail := network.(map[string]interface{})
           NetworkConfig: &types.VAppNetworkConfiguration{
             NetworkName: detail["network_name"].(string),
             Configuration: &types.NetworkConfiguration{
               ParentNetwork: &types.Reference{
                 HREF: detail["network_href"],
               },
               FenceMode: "bridged",
             },
           },
         },
       },

but I get the error:
expected operand, found 'for'

so I guess I can't do it like this...

Help!

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Matthew Singletary at Apr 25, 2016 at 3:06 pm
    Are you defining the type or are you using some api?

    If you can have multiple NetConfigs, then build up a slice in a for loop
    before the struct literal and then put it in the literal.

    var vancs []*types.VAppNetworkConfiguration
    for _,network := range resolved_net_info {
               detail := network.(map[string]interface{})
               vancs = vancs(append,
                 NetworkConfig: &types.VAppNetworkConfiguration{
                 NetworkName: detail["network_name"].(string),
                 Configuration: &types.NetworkConfiguration{
                   ParentNetwork: &types.Reference{
                     HREF: detail["network_href"], // you might need to convert
    this type
                   },
                   FenceMode: "bridged",
                 },
               })
             },

    createvapp := &types.InstantiateVAppTemplateParams{
    Ovf: "http://schemas.dmtf.org/ovf/envelope/1",
    Xmlns: "http://www.vmware.com/vcloud/v1.5",
    Name: d.Get("name").(string),
    InstantiationParams: &types.InstantiationParams{
    NetworkConfigSection: &types.NetworkConfigSection{
    Info: "Configuration parameters for logical networks",
                                     // notice a slice of pointers
                                     NetworkConfigs: vancs
    },
    },
    Source: &types.Reference{
    HREF: vapptemplate.VAppTemplate.HREF,
    },
    }


    The main issue is the struct type needs to allow multiple configs though.



    mån 25 apr. 2016 kl 10:51 skrev <tim.lawrence1984@gmail.com>:
    Hi,

    sorry if this is a dumb question but I am very new to Go and not even that
    sure how to phrase the question.

    I am working on adding features to a Terraform provider and the existing
    code defines the following:

    createvapp := &types.InstantiateVAppTemplateParams{
    Ovf: "http://schemas.dmtf.org/ovf/envelope/1",
    Xmlns: "http://www.vmware.com/vcloud/v1.5",
    Name: d.Get("name").(string),
    InstantiationParams: &types.InstantiationParams{
    NetworkConfigSection: &types.NetworkConfigSection{
    Info: "Configuration parameters for logical networks",
    NetworkConfig:
    &types.VAppNetworkConfiguration{
    NetworkName: d.Get("network_name").(string),
    Configuration: &types.NetworkConfiguration{
    ParentNetwork: &types.Reference{
    HREF: networkHref,
    },
    FenceMode: "bridged",
    },
    },
    Source: &types.Reference{
    HREF: vapptemplate.VAppTemplate.HREF,
    },
    }



    I need to refactor this so that I can pass in a variable number of
    "NetworkConfig" types from a stored map.

    In Ruby I would do something like:

    NetworkConfigSection: &types.NetworkConfigSection{
    Info: "Configuration parameters for logical networks",
    for _,network := range resolved_net_info {
    detail := network.(map[string]interface{})
    NetworkConfig: &types.VAppNetworkConfiguration{
    NetworkName: detail["network_name"].(string),
    Configuration: &types.NetworkConfiguration{
    ParentNetwork: &types.Reference{
    HREF: detail["network_href"],
    },
    FenceMode: "bridged",
    },
    },
    },
    },

    but I get the error:
    expected operand, found 'for'

    so I guess I can't do it like this...

    Help!

    --
    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+unsubscribe@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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedApr 25, '16 at 2:51p
activeApr 25, '16 at 3:06p
posts2
users2
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase