github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/runtime/generic_component_disabler.go (about) 1 package runtime 2 3 import "github.com/kyma-project/kyma-environment-broker/internal" 4 5 // GenericComponentDisabler provides functionality for removing configured component from given list 6 type GenericComponentDisabler struct { 7 componentName string 8 } 9 10 // NewGenericComponentDisabler returns new instance of GenericComponentDisabler 11 func NewGenericComponentDisabler(name string) *GenericComponentDisabler { 12 return &GenericComponentDisabler{componentName: name} 13 } 14 15 // Disable removes component form given lists. Filtering without allocating. 16 // 17 // source: https://github.com/golang/go/wiki/SliceTricks#filtering-without-allocating 18 func (g *GenericComponentDisabler) Disable(components internal.ComponentConfigurationInputList) internal.ComponentConfigurationInputList { 19 filterOut := components[:0] 20 for _, component := range components { 21 if !g.shouldRemove(component.Component) { 22 filterOut = append(filterOut, component) 23 } 24 } 25 26 for i := len(filterOut); i < len(components); i++ { 27 components[i] = nil 28 } 29 30 return filterOut 31 } 32 33 func (g *GenericComponentDisabler) shouldRemove(in string) bool { 34 return in == g.componentName 35 }