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