open-consul/agent/configentry/config_entry.go
R.B. Boyer 11fdc70b34
configentry: make a new package to hold shared config entry structs that aren't used for RPC or the FSM (#12384)
First two candidates are ConfigEntryKindName and DiscoveryChainConfigEntries.
2022-02-22 10:36:36 -06:00

35 lines
807 B
Go

package configentry
import (
"github.com/hashicorp/consul/agent/structs"
)
// KindName is a value type useful for maps. You can use:
// map[KindName]Payload
// instead of:
// map[string]map[string]Payload
type KindName struct {
Kind string
Name string
structs.EnterpriseMeta
}
// NewKindName returns a new KindName. The EnterpriseMeta values will be
// normalized based on the kind.
//
// Any caller which modifies the EnterpriseMeta field must call Normalize
// before persisting or using the value as a map key.
func NewKindName(kind, name string, entMeta *structs.EnterpriseMeta) KindName {
ret := KindName{
Kind: kind,
Name: name,
}
if entMeta == nil {
entMeta = structs.DefaultEnterpriseMetaInDefaultPartition()
}
ret.EnterpriseMeta = *entMeta
ret.Normalize()
return ret
}