2020-03-17 06:14:32 -04:00
|
|
|
//go:generate mapstructure-to-hcl2 -type NameValue,NameValues,KVFilter
|
2020-03-13 11:04:42 -04:00
|
|
|
|
|
|
|
package hcl2template
|
|
|
|
|
2020-03-17 06:14:32 -04:00
|
|
|
type NameValue struct {
|
|
|
|
Name string
|
2020-03-13 11:04:42 -04:00
|
|
|
Value string
|
|
|
|
}
|
2020-03-13 12:17:00 -04:00
|
|
|
|
2020-03-17 06:14:32 -04:00
|
|
|
type NameValues []NameValue
|
2020-03-13 13:04:48 -04:00
|
|
|
|
2020-03-17 06:14:32 -04:00
|
|
|
func (kvs NameValues) CopyOn(to *map[string]string) []error {
|
2020-03-16 10:46:08 -04:00
|
|
|
if *to == nil {
|
|
|
|
*to = map[string]string{}
|
|
|
|
}
|
2020-03-13 13:04:48 -04:00
|
|
|
for _, kv := range kvs {
|
2020-03-17 06:14:32 -04:00
|
|
|
(*to)[kv.Name] = kv.Value
|
2020-03-13 13:04:48 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-03-13 12:17:00 -04:00
|
|
|
type KVFilter struct {
|
|
|
|
Filters map[string]string
|
2020-03-17 06:14:32 -04:00
|
|
|
Filter NameValues
|
2020-03-13 12:17:00 -04:00
|
|
|
}
|
|
|
|
|
2020-03-13 13:04:48 -04:00
|
|
|
func (kvf *KVFilter) Prepare() []error {
|
2020-03-16 10:46:08 -04:00
|
|
|
kvf.Filter.CopyOn(&kvf.Filters)
|
2020-03-13 12:17:00 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (kvf *KVFilter) Empty() bool {
|
|
|
|
return len(kvf.Filters) == 0
|
|
|
|
}
|