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

util.go 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. }
  34. // Max max of two ints
  35. func Max(a, b int) int {
  36. if a < b {
  37. return b
  38. }
  39. return a
  40. }
  41. // Min min of two ints
  42. func Min(a, b int) int {
  43. if a > b {
  44. return b
  45. }
  46. return a
  47. }