2018-12-19 07:20
浏览 349


I'm newbie with Golang.

I want to create a list of dictionaries with resizable capability (this is not static) with append some dict to the list, finally write it on a file, but I confused.

I want something like that:

 {"port": 161, "timeout": 1, "sleep_time": 5, "metrics": [
  {"tag_name": "output_current", "id": 3},
  {"tag_name": "input_voltage", "id": 2}
 {"port": 161, "timeout": 1, "sleep_time": 4, "metrics": [
   {"tag_name": "destructor", "id": 10}


What is the .append() Python equivalent in Go language something like that?

list_ = []
dict_ = {"key": val}

I found the answer to this section ([UPDATE]) by borrowing this answer:

type Dictionary map[string]interface{}
data := []Dictionary{}
dict1 := Dictionary{"key": 1}
dict2 := Dictionary{"key": 2}
data = append(data, dict1, dict2)

2条回答 默认 最新

相关推荐 更多相似问题