gutil_default.go 912 B

123456789101112131415161718192021222324252627
  1. // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
  2. //
  3. // This Source Code Form is subject to the terms of the MIT License.
  4. // If a copy of the MIT was not distributed with this file,
  5. // You can obtain one at https://github.com/gogf/gf.
  6. package gutil
  7. // GetOrDefaultStr checks and returns value according whether parameter `param` available.
  8. // It returns `param[0]` if it is available, or else it returns `def`.
  9. func GetOrDefaultStr(def string, param ...string) string {
  10. value := def
  11. if len(param) > 0 && param[0] != "" {
  12. value = param[0]
  13. }
  14. return value
  15. }
  16. // GetOrDefaultAny checks and returns value according whether parameter `param` available.
  17. // It returns `param[0]` if it is available, or else it returns `def`.
  18. func GetOrDefaultAny(def interface{}, param ...interface{}) interface{} {
  19. value := def
  20. if len(param) > 0 && param[0] != "" {
  21. value = param[0]
  22. }
  23. return value
  24. }