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:
James Shubin
2016-03-14 01:43:02 -04:00
parent d1315bb092
commit 659fb3eb82

View File

@@ -67,18 +67,14 @@ 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? // XXX should default to true
} }
type Res interface { // this interface is everything that is common to all resources
Init() // everything here only needs to be implemented once, in the BaseRes
GetName() string // can't be named "Name()" because of struct field type Base interface {
GetUUIDs() []ResUUID // most resources only return one GetName() string // can't be named "Name()" because of struct field
GetMeta() MetaParams
Kind() string Kind() string
Watch() GetMeta() MetaParams
CheckApply(bool) (bool, error)
AutoEdges() AutoEdge
SetVertex(*Vertex) SetVertex(*Vertex)
SetConvergedCallback(ctimeout int, converged chan bool) SetConvergedCallback(ctimeout int, converged chan bool)
Compare(Res) bool
SendEvent(eventName, bool, bool) bool SendEvent(eventName, bool, bool) bool
IsWatching() bool IsWatching() bool
SetWatching(bool) SetWatching(bool)
@@ -93,6 +89,18 @@ type Res interface {
BackPoke() 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 { type BaseRes struct {
Name string `yaml:"name"` Name string `yaml:"name"`
Meta MetaParams `yaml:"meta"` // struct of all the metaparams Meta MetaParams `yaml:"meta"` // struct of all the metaparams