resources: Set the defaults for metaparameters
This now lets us have defaults for metaparameters that aren't the zero value for that type.
This commit is contained in:
@@ -70,8 +70,8 @@ type AutoEdge interface {
|
|||||||
|
|
||||||
// MetaParams is a struct will all params that apply to every resource.
|
// MetaParams is a struct will all params that apply to every resource.
|
||||||
type MetaParams struct {
|
type MetaParams struct {
|
||||||
AutoEdge bool `yaml:"autoedge"` // metaparam, should we generate auto edges? // XXX: should default to true
|
AutoEdge bool `yaml:"autoedge"` // metaparam, should we generate auto edges?
|
||||||
AutoGroup bool `yaml:"autogroup"` // metaparam, should we auto group? // XXX: should default to true
|
AutoGroup bool `yaml:"autogroup"` // metaparam, should we auto group?
|
||||||
Noop bool `yaml:"noop"`
|
Noop bool `yaml:"noop"`
|
||||||
// NOTE: there are separate Watch and CheckApply retry and delay values,
|
// NOTE: there are separate Watch and CheckApply retry and delay values,
|
||||||
// but I've decided to use the same ones for both until there's a proper
|
// but I've decided to use the same ones for both until there's a proper
|
||||||
@@ -80,6 +80,29 @@ type MetaParams struct {
|
|||||||
Delay uint64 `yaml:"delay"` // metaparam, number of milliseconds to wait between retries
|
Delay uint64 `yaml:"delay"` // metaparam, number of milliseconds to wait between retries
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnmarshalYAML is the custom unmarshal handler for the MetaParams struct. It
|
||||||
|
// is primarily useful for setting the defaults.
|
||||||
|
func (obj *MetaParams) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
|
type rawMetaParams MetaParams // indirection to avoid infinite recursion
|
||||||
|
raw := rawMetaParams(DefaultMetaParams) // convert; the defaults go here
|
||||||
|
|
||||||
|
if err := unmarshal(&raw); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
*obj = MetaParams(raw) // restore from indirection with type conversion!
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DefaultMetaParams are the defaults to be used for undefined metaparams.
|
||||||
|
var DefaultMetaParams = MetaParams{
|
||||||
|
AutoEdge: true,
|
||||||
|
AutoGroup: true,
|
||||||
|
Noop: false,
|
||||||
|
Retry: 0, // TODO: is this a good default?
|
||||||
|
Delay: 0, // TODO: is this a good default?
|
||||||
|
}
|
||||||
|
|
||||||
// The Base interface is everything that is common to all resources.
|
// The Base interface is everything that is common to all resources.
|
||||||
// Everything here only needs to be implemented once, in the BaseRes.
|
// Everything here only needs to be implemented once, in the BaseRes.
|
||||||
type Base interface {
|
type Base interface {
|
||||||
|
|||||||
Reference in New Issue
Block a user