types/opt: add Bool.EqualBool method

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2020-06-25 19:07:38 -07:00
committed by Brad Fitzpatrick
parent 4732722b87
commit 0071888a17
2 changed files with 30 additions and 0 deletions
+7
View File
@@ -29,6 +29,13 @@ func (b Bool) Get() (v bool, ok bool) {
return v, err == nil
}
// EqualBool reports whether b is equal to v.
// If b is empty or not a valid bool, it reports false.
func (b Bool) EqualBool(v bool) bool {
p, ok := b.Get()
return ok && p == v
}
var (
trueBytes = []byte("true")
falseBytes = []byte("false")