Split the Res interface into a Base sub piece
I didn't know this was possible until I was browsing through some golang docs recently. This should hopefully make it clearer which the common methods to all resources are (which don't need to be reimplemented each time) and which ones are unique and need to be created for each resource.
This commit is contained in:
26
resources.go
26
resources.go
@@ -67,18 +67,14 @@ type MetaParams struct {
|
||||
AutoEdge bool `yaml:"autoedge"` // metaparam, should we generate auto edges? // XXX should default to true
|
||||
}
|
||||
|
||||
type Res interface {
|
||||
Init()
|
||||
GetName() string // can't be named "Name()" because of struct field
|
||||
GetUUIDs() []ResUUID // most resources only return one
|
||||
GetMeta() MetaParams
|
||||
// this interface is everything that is common to all resources
|
||||
// everything here only needs to be implemented once, in the BaseRes
|
||||
type Base interface {
|
||||
GetName() string // can't be named "Name()" because of struct field
|
||||
Kind() string
|
||||
Watch()
|
||||
CheckApply(bool) (bool, error)
|
||||
AutoEdges() AutoEdge
|
||||
GetMeta() MetaParams
|
||||
SetVertex(*Vertex)
|
||||
SetConvergedCallback(ctimeout int, converged chan bool)
|
||||
Compare(Res) bool
|
||||
SendEvent(eventName, bool, bool) bool
|
||||
IsWatching() bool
|
||||
SetWatching(bool)
|
||||
@@ -93,6 +89,18 @@ type Res interface {
|
||||
BackPoke()
|
||||
}
|
||||
|
||||
// this is the minimum interface you need to implement to make a new resource
|
||||
type Res interface {
|
||||
Base // include everything from the Base interface
|
||||
Init()
|
||||
//Validate() bool // TODO: this might one day be added
|
||||
GetUUIDs() []ResUUID // most resources only return one
|
||||
Watch()
|
||||
CheckApply(bool) (bool, error)
|
||||
AutoEdges() AutoEdge
|
||||
Compare(Res) bool
|
||||
}
|
||||
|
||||
type BaseRes struct {
|
||||
Name string `yaml:"name"`
|
||||
Meta MetaParams `yaml:"meta"` // struct of all the metaparams
|
||||
|
||||
Reference in New Issue
Block a user