terraform-provider-gitea/vendor/github.com/hashicorp/terraform-plugin-log/internal/hclogutils/args.go
Tobias Trabelsi e1266ebf64
Some checks reported errors
continuous-integration/drone/pr Build encountered an error
continuous-integration/drone/push Build encountered an error
updated GHA
Update to v2 SDK
updated dependencies
2022-08-06 16:21:18 +02:00

27 lines
710 B
Go

package hclogutils
import (
"github.com/hashicorp/terraform-plugin-log/internal/fieldutils"
)
// FieldMapsToArgs will shallow merge field maps into a slice of key/value pairs
// arguments (i.e. `[k1, v1, k2, v2, ...]`) expected by hc-log.Logger methods.
func FieldMapsToArgs(maps ...map[string]interface{}) []interface{} {
switch len(maps) {
case 0:
return nil
case 1:
result := make([]interface{}, 0, len(maps[0])*2)
for k, v := range maps[0] {
result = append(result, k, v)
}
return result
default:
// As we merge all maps into one, we can use this
// same function recursively, falling back on the `switch case 1`.
return FieldMapsToArgs(fieldutils.MergeFieldMaps(maps...))
}
}