github.com/banzaicloud/operator-tools@v0.28.10/pkg/helm/strimap.go (about) 1 // Copyright © 2020 Banzai Cloud 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package helm 16 17 type Strimap = map[string]interface{} 18 19 type StrimapBuilder Strimap 20 21 func (s StrimapBuilder) Getin(strs ...string) Strimap { 22 if s == nil || len(strs) == 0 { 23 return nil 24 } 25 26 submap, ok := s[strs[0]].(Strimap) 27 if !ok { 28 return nil 29 } 30 31 if len(strs[1:]) > 0 { 32 return StrimapBuilder(submap).Getin(strs[1:]...) 33 } 34 return submap 35 } 36 37 func MergeMaps(a, b Strimap) Strimap { 38 out := make(Strimap, len(a)) 39 for k, v := range a { 40 out[k] = v 41 } 42 for k, v := range b { 43 if v, ok := v.(Strimap); ok { 44 if bv, ok := out[k]; ok { 45 if bv, ok := bv.(Strimap); ok { 46 out[k] = MergeMaps(bv, v) 47 continue 48 } 49 } 50 } 51 out[k] = v 52 } 53 return out 54 }