packer-cn/hcl2template/types.kv.go

38 lines
626 B
Go
Raw Normal View History

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