add WithCheck
This commit is contained in:
parent
ee2f4e82a1
commit
5e49842e6f
20
main.go
20
main.go
|
@ -16,4 +16,24 @@ type (
|
||||||
// state.
|
// state.
|
||||||
Ensure() error
|
Ensure() error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkEnsurer struct {
|
||||||
|
Is Enforced
|
||||||
|
State Ensurer
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// WithCheck creates an Ensurer instance that runs is before Ensure.
|
||||||
|
func WithCheck(is Enforced, en Ensurer) Ensurer {
|
||||||
|
return &checkEnsurer{
|
||||||
|
Is: is,
|
||||||
|
State: en,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *checkEnsurer) Ensure() error {
|
||||||
|
if !c.Is() {
|
||||||
|
return c.State.Ensure()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue