Golang create a slice of maps

I was trying to create a slice of maps the following way.

keyvalue := make(map[string]interface{})
keyvalueslice := make([]keyvalue, 1, 1)

I was trying to create it just like the way string slice is created, however I am getting an error saying keyvalue is not a type. I am creating this slice to append data to keyvalueslice variable later.

Can someone explain what is wrong?

Answers


keyvalue is a variable not a type, you can't create a slice of variables. If you want to define custom type you can do this like

type keyvalue map[string]interface{}

then you can create a slice of keyvalues:

keyvalueslice := make([]keyvalue, 1, 1)

Example on playground

Or you can do this without defining custom type:

keyvalueslice := make([]map[string]interface{}, 1, 1)

Need Your Help

MOSS SpNavigationNode.Children always empty

sharepoint navigation

I'm trying to return all the child nodes of a set of navigation nodes in sharepoint, the SDK implies I should be doing something like this:

Jconsole live threads count and java ExecutorService

java executorservice jconsole

Monitoring our app using JConsole over a period of time shows that the “live thread” count is increasing constantly. Increasing thread count sounds like a bad thing to me, or am I wrong?