add WithCheck

This commit is contained in:
Gibheer 2020-04-21 21:20:35 +02:00
parent ee2f4e82a1
commit 5e49842e6f
1 changed files with 20 additions and 0 deletions

20
main.go
View File

@ -16,4 +16,24 @@ type (
// state.
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
}