switch around the WithCheck function
It should be better with an interface. That way it can be written as ensure.WithCheck(resource)
This commit is contained in:
parent
5e49842e6f
commit
ef72359b2d
15
main.go
15
main.go
|
@ -17,22 +17,27 @@ type (
|
|||
Ensure() error
|
||||
}
|
||||
|
||||
// CheckEnsurer is an etension of ensurer, which also provides an Is function
|
||||
// to check the state of the resource.
|
||||
CheckEnsurer interface {
|
||||
Is() bool
|
||||
Ensure() error
|
||||
}
|
||||
|
||||
checkEnsurer struct {
|
||||
Is Enforced
|
||||
State Ensurer
|
||||
State CheckEnsurer
|
||||
}
|
||||
)
|
||||
|
||||
// WithCheck creates an Ensurer instance that runs is before Ensure.
|
||||
func WithCheck(is Enforced, en Ensurer) Ensurer {
|
||||
func WithCheck(en CheckEnsurer) Ensurer {
|
||||
return &checkEnsurer{
|
||||
Is: is,
|
||||
State: en,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *checkEnsurer) Ensure() error {
|
||||
if !c.Is() {
|
||||
if !c.State.Is() {
|
||||
return c.State.Ensure()
|
||||
}
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue