## Description replaces the common/maps.go code with the golang experimental maps package. The maps package provides standard api such as Keys, Values, Copy, and Clone. https://pkg.go.dev/golang.org/x/exp/maps ## Does this PR need a docs update or release note? - [x] ⛔ No ## Type of change - [x] 🐹 Trivial/Minor ## Test Plan - [x] ⚡ Unit test
25 lines
490 B
Go
25 lines
490 B
Go
package common
|
|
|
|
import "golang.org/x/exp/maps"
|
|
|
|
type StringConfigurer interface {
|
|
StringConfig() (map[string]string, error)
|
|
}
|
|
|
|
// UnionStringConfigs unions all provided configurers into a single
|
|
// map[string]string matching type.
|
|
func UnionStringConfigs(cfgs ...StringConfigurer) (map[string]string, error) {
|
|
union := map[string]string{}
|
|
|
|
for _, cfg := range cfgs {
|
|
c, err := cfg.StringConfig()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
maps.Copy(union, c)
|
|
}
|
|
|
|
return union, nil
|
|
}
|