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

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

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

Okay