Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

util.go 994B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. }