Resources: Update interface to support errors

This was an early interface mistake I made and is now corrected.
We'll plumb in checking the error state of Init() and running Validate()
later on.
This commit is contained in:
James Shubin
2016-09-27 05:15:28 -04:00
parent ad3c6bdc88
commit ccc00f913d
7 changed files with 40 additions and 42 deletions

View File

@@ -59,20 +59,20 @@ func NewSvcRes(name, state, startup string) *SvcRes {
}
// Init runs some startup code for this resource.
func (obj *SvcRes) Init() {
func (obj *SvcRes) Init() error {
obj.BaseRes.kind = "Svc"
obj.BaseRes.Init() // call base init, b/c we're overriding
return obj.BaseRes.Init() // call base init, b/c we're overriding
}
// Validate checks if the resource data structure was populated correctly.
func (obj *SvcRes) Validate() bool {
func (obj *SvcRes) Validate() error {
if obj.State != "running" && obj.State != "stopped" && obj.State != "" {
return false
return fmt.Errorf("State must be either `running` or `stopped` or undefined.")
}
if obj.Startup != "enabled" && obj.Startup != "disabled" && obj.Startup != "" {
return false
return fmt.Errorf("Startup must be either `enabled` or `disabled` or undefined.")
}
return true
return nil
}
// Watch is the primary listener for this resource and it outputs events.