DEV Community

Dinesh Chavan
Dinesh Chavan

Posted on

Golang array

Hi Experts,
Am new to Golang and stuck with calling array element in Golang, on internet i don't find any example of array element with user inputs.
Here is the snippet of function which is getting failed during compile.

func resourceRoleManagementCreate(d *schema.ResourceData, meta interface{}) error {
    config := meta.(Config)
  resourceAction := "create"
  rc := &RoleCreate{
    Action: resourceAction,
    Resources: RoleCreateConfig{
      Name: d.Get("name").(string),
            Settings: SettingsConfig{
        Restrictions: Restrictions{
                    Vms: d.Get("vms").(string),
                },
      },
            Features: FeaturesConfig{
        Identifier: d.Get("identifier").(string),
      },
    },
  }

Enter fullscreen mode Exit fullscreen mode

Schema definition is as below:

// RoleConfig for Role Management
type RoleCreate struct {
    Action   string        `json:"action"`
    Resources  RoleCreateConfig   `json:"resources"`
}

type FeaturesConfig struct {
    Identifier string `json:"identifier"`
}

type RoleCreateConfig struct {
    Name     string     `json:"name"`
    Settings SettingsConfig   `json:"settings"`
    Features []FeaturesConfig `json:"features"`
}

type SettingsConfig struct {
    Restrictions Restrictions `json:"restrictions"`
}

type Restrictions struct {
    Vms string `json:"vms"`
}
Enter fullscreen mode Exit fullscreen mode

Error am getting while compiling is as below:

infra8/resource_role_management.go:58:14: cannot use FeaturesConfig{…} (value of type FeaturesConfig) as type []FeaturesConfig in struct literal
make: *** [build] Error 2
Enter fullscreen mode Exit fullscreen mode

Top comments (0)