Пример #1
0
func filterDottedKeys(data map[interface{}]interface{}, keys []string) (filtered, rest map[interface{}]interface{}) {
	filtered = map[interface{}]interface{}{}
	rest = util.MapCopy(data)

	for _, key := range keys {
		f, r := filterKey(data, strings.Split(key, "."))
		filtered = util.MapsUnion(filtered, f)
		rest = util.MapsIntersection(rest, r)
	}

	return
}
Пример #2
0
func TestMapsIntersection(t *testing.T) {
	assert := require.New(t)

	m0 := map[interface{}]interface{}{"a": 1, "b": map[interface{}]interface{}{"c": 3}, "d": "4"}
	m1 := util.MapCopy(m0)

	delete(m0, "a")
	b1 := m1["b"].(map[interface{}]interface{})
	delete(b1, "c")
	expected := map[interface{}]interface{}{"b": map[interface{}]interface{}{}, "d": "4"}
	assert.Equal(expected, util.MapsIntersection(m0, m1, util.Equal))
}