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

util.go 1.1KB

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