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

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay