maxmind/mmdbwriter

How to create array in subdivisions element?

Closed this issue · 1 comments

I am very new to both Go and the inner workings of MaxMind DB. My goal is to merge my private IP ranges into an existing City MMDB. I have been able to insert most data elements but I have not figured out how to add subdivisions as a JSON array in Go.

This does not produce an array:

		recordData := mmdbtype.Map{
			"city": mmdbtype.Map{
				"names": mmdbtype.Map{
					"en": mmdbtype.String(vlanLoc.City + ": " + vlanLoc.AdNet),
				},
			},
			"subdivisions": mmdbtype.Map{
				"iso_code": mmdbtype.String(vlanLoc.Province),
				"names": mmdbtype.Map{
					"en": mmdbtype.String("subdivison data here"),
				},
			},

Putting array brackets "[]" in from of the "mmdbtype.Map" triggers this error in the compiler.

cannot use []mmdbtype.Map literal (type []mmdbtype.Map) as type mmdbtype.DataType in map value:
	[]mmdbtype.Map does not implement mmdbtype.DataType (missing Copy method)

Example of the above:

		subdivisions := make([]mmdbtype.Map, 1)
		subdivisions[0] = mmdbtype.Map{
			"iso_code": mmdbtype.String(vlanLoc.Province),
			"names":    mmdbtype.Map{"en": mmdbtype.String("subdivison data here")},
		}

		recordData := mmdbtype.Map{
			"city": mmdbtype.Map{
				"names": mmdbtype.Map{
					"en": mmdbtype.String(vlanLoc.City + ": " + vlanLoc.AdNet),
				},
			},
			"subdivisions": subdivisions,

How can this be constructed so that an array like the following is added to the MMDB?

                    "subdivisions": [
                        {
                            "geoname_id": 5128638,
                            "iso_code": "NY",
                            "names": {
                                "de": "New York",
                                "en": "New York",
                            }
                        }
                    ]

Slices!

		recordData := mmdbtype.Map{
			"city": mmdbtype.Map{
				"names": mmdbtype.Map{
					"en": mmdbtype.String(vlanLoc.City + ": " + vlanLoc.AdNet),
				},
			},
			"subdivisions": mmdbtype.Slice{
				mmdbtype.Map{
					"iso_code": mmdbtype.String(vlanLoc.Province),
					"names":    mmdbtype.Map{"en": mmdbtype.String("subdivison 1? data here")},
				},
				mmdbtype.Map{
					"iso_code": mmdbtype.String(vlanLoc.Province),
					"names":    mmdbtype.Map{"en": mmdbtype.String("subdivison 2? data here")},
				},
			},