Skip to content

Addresses of Items in Slice with Get()Β #196

@jakdept

Description

@jakdept

Let's say I have a json config that looks like the following, and I load it in:

{
  "slice": [
    {
      "name": "apple",
      "type": "fruit",
      "serving": 1
    },
    {
      "name": "banana",
      "type": "fruit",
      "serving": 1
    },
    {
      "name": "grape",
      "type": "fruit",
      "serving": 6
    },
    {
      "name": "carrot",
      "type": "veggie",
      "serving": 1
    },
    {
      "name": "broccoli",
      "type": "veggie",
      "serving": 1
    }
  ]
}

How, using Get(), would I access slice.2.serving - the serving size for grapes? I would expect that, but I honestly don't know. Is the same string used for GetInt() to access that same location? I didn't see any tests that looked to be referencing an index either.

I've looked through the docs, and I don't really see where it's specified how to get at items within a slice - I saw a lot of named stuff, lots of map[string]interface{}, but no slices.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions