github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/core/life/life.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package life 5 6 import ( 7 "github.com/juju/errors" 8 ) 9 10 // Value indicates the state of some entity. 11 type Value string 12 13 const ( 14 // Alive indicates that some entity is meant to exist. 15 Alive Value = "alive" 16 17 // Dying indicates that some entity should be removed. 18 Dying Value = "dying" 19 20 // Dead indicates that some entity is no longer useful, 21 // and can be destroyed unconditionally. 22 Dead Value = "dead" 23 ) 24 25 // Validate returns an error if the value is not known. 26 func (v Value) Validate() error { 27 switch v { 28 case Alive, Dying, Dead: 29 return nil 30 } 31 return errors.NotValidf("life value %q", v) 32 } 33 34 // Predicate is a predicate. 35 type Predicate func(Value) bool 36 37 // IsNotAlive is a Predicate that returns true if the supplied value 38 // is not Alive. 39 // 40 // This generally indicates that the entity in question is at some 41 // stage of destruction/cleanup. 42 func IsNotAlive(v Value) bool { 43 return v != Alive 44 } 45 46 // IsNotDead is a Predicate that returns true if the supplied value 47 // is not Dead. 48 // 49 // This generally indicates that the entity in question is active in 50 // some way, and can probably not be completely destroyed without 51 // consequences. 52 func IsNotDead(v Value) bool { 53 return v != Dead 54 }