g_func.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2017 gf Author(https://github.com/gogf/gf). 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 g
  7. import (
  8. "github.com/gogf/gf/container/gvar"
  9. "github.com/gogf/gf/internal/empty"
  10. "github.com/gogf/gf/net/ghttp"
  11. "github.com/gogf/gf/util/gutil"
  12. )
  13. // NewVar returns a gvar.Var.
  14. func NewVar(i interface{}, safe ...bool) *Var {
  15. return gvar.New(i, safe...)
  16. }
  17. // Wait blocks until all the web servers shutdown.
  18. func Wait() {
  19. ghttp.Wait()
  20. }
  21. // Dump dumps a variable to stdout with more manually readable.
  22. func Dump(i ...interface{}) {
  23. gutil.Dump(i...)
  24. }
  25. // Export exports a variable to string with more manually readable.
  26. func Export(i ...interface{}) string {
  27. return gutil.Export(i...)
  28. }
  29. // Throw throws a exception, which can be caught by TryCatch function.
  30. // It always be used in TryCatch function.
  31. func Throw(exception interface{}) {
  32. gutil.Throw(exception)
  33. }
  34. // Try implements try... logistics using internal panic...recover.
  35. // It returns error if any exception occurs, or else it returns nil.
  36. func Try(try func()) (err error) {
  37. return gutil.Try(try)
  38. }
  39. // TryCatch implements try...catch... logistics using internal panic...recover.
  40. // It automatically calls function <catch> if any exception occurs ans passes the exception as an error.
  41. func TryCatch(try func(), catch ...func(exception error)) {
  42. gutil.TryCatch(try, catch...)
  43. }
  44. // IsNil checks whether given <value> is nil.
  45. // Note that it might use reflect feature which affects performance a little bit.
  46. func IsNil(value interface{}) bool {
  47. return empty.IsNil(value)
  48. }
  49. // IsEmpty checks whether given <value> empty.
  50. // It returns true if <value> is in: 0, nil, false, "", len(slice/map/chan) == 0.
  51. // Or else it returns true.
  52. func IsEmpty(value interface{}) bool {
  53. return empty.IsEmpty(value)
  54. }