You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

util.go 994 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package util
  5. // OptionalBool a boolean that can be "null"
  6. type OptionalBool byte
  7. const (
  8. // OptionalBoolNone a "null" boolean value
  9. OptionalBoolNone = iota
  10. // OptionalBoolTrue a "true" boolean value
  11. OptionalBoolTrue
  12. // OptionalBoolFalse a "false" boolean value
  13. OptionalBoolFalse
  14. )
  15. // IsTrue return true if equal to OptionalBoolTrue
  16. func (o OptionalBool) IsTrue() bool {
  17. return o == OptionalBoolTrue
  18. }
  19. // IsFalse return true if equal to OptionalBoolFalse
  20. func (o OptionalBool) IsFalse() bool {
  21. return o == OptionalBoolFalse
  22. }
  23. // IsNone return true if equal to OptionalBoolNone
  24. func (o OptionalBool) IsNone() bool {
  25. return o == OptionalBoolNone
  26. }
  27. // OptionalBoolOf get the corresponding OptionalBool of a bool
  28. func OptionalBoolOf(b bool) OptionalBool {
  29. if b {
  30. return OptionalBoolTrue
  31. }
  32. return OptionalBoolFalse
  33. }