From 659fb3eb82a1ca4a1a9fde7840b35c7e48b7a189 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Mon, 14 Mar 2016 01:43:02 -0400 Subject: [PATCH] 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. --- resources.go | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/resources.go b/resources.go index 51ebb84a..45cae45d 100644 --- a/resources.go +++ b/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