g_object.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 g
  7. import (
  8. "github.com/gogf/gf/database/gdb"
  9. "github.com/gogf/gf/database/gredis"
  10. "github.com/gogf/gf/frame/gins"
  11. "github.com/gogf/gf/i18n/gi18n"
  12. "github.com/gogf/gf/net/ghttp"
  13. "github.com/gogf/gf/net/gtcp"
  14. "github.com/gogf/gf/net/gudp"
  15. "github.com/gogf/gf/os/gcfg"
  16. "github.com/gogf/gf/os/glog"
  17. "github.com/gogf/gf/os/gres"
  18. "github.com/gogf/gf/os/gview"
  19. "github.com/gogf/gf/util/gvalid"
  20. )
  21. // Client is a convenience function, which creates and returns a new HTTP client.
  22. func Client() *ghttp.Client {
  23. return ghttp.NewClient()
  24. }
  25. // Server returns an instance of http server with specified name.
  26. func Server(name ...interface{}) *ghttp.Server {
  27. return gins.Server(name...)
  28. }
  29. // TCPServer returns an instance of tcp server with specified name.
  30. func TCPServer(name ...interface{}) *gtcp.Server {
  31. return gtcp.GetServer(name...)
  32. }
  33. // UDPServer returns an instance of udp server with specified name.
  34. func UDPServer(name ...interface{}) *gudp.Server {
  35. return gudp.GetServer(name...)
  36. }
  37. // View returns an instance of template engine object with specified name.
  38. func View(name ...string) *gview.View {
  39. return gins.View(name...)
  40. }
  41. // Config returns an instance of config object with specified name.
  42. func Config(name ...string) *gcfg.Config {
  43. return gins.Config(name...)
  44. }
  45. // Cfg is alias of Config.
  46. // See Config.
  47. func Cfg(name ...string) *gcfg.Config {
  48. return Config(name...)
  49. }
  50. // Resource returns an instance of Resource.
  51. // The parameter <name> is the name for the instance.
  52. func Resource(name ...string) *gres.Resource {
  53. return gins.Resource(name...)
  54. }
  55. // I18n returns an instance of gi18n.Manager.
  56. // The parameter <name> is the name for the instance.
  57. func I18n(name ...string) *gi18n.Manager {
  58. return gins.I18n(name...)
  59. }
  60. // Res is alias of Resource.
  61. // See Resource.
  62. func Res(name ...string) *gres.Resource {
  63. return Resource(name...)
  64. }
  65. // Log returns an instance of glog.Logger.
  66. // The parameter <name> is the name for the instance.
  67. func Log(name ...string) *glog.Logger {
  68. return gins.Log(name...)
  69. }
  70. // DB returns an instance of database ORM object with specified configuration group name.
  71. func DB(name ...string) gdb.DB {
  72. return gins.Database(name...)
  73. }
  74. // Table is alias of Model.
  75. // The database component is designed not only for
  76. // relational databases but also for NoSQL databases in the future. The name
  77. // "Table" is not proper for that purpose any more.
  78. // Deprecated, use Model instead.
  79. func Table(tableNameOrStruct ...interface{}) *gdb.Model {
  80. return DB().Model(tableNameOrStruct...)
  81. }
  82. // Model creates and returns a model based on configuration of default database group.
  83. func Model(tableNameOrStruct ...interface{}) *gdb.Model {
  84. return DB().Model(tableNameOrStruct...)
  85. }
  86. // Redis returns an instance of redis client with specified configuration group name.
  87. func Redis(name ...string) *gredis.Redis {
  88. return gins.Redis(name...)
  89. }
  90. // Validator is a convenience function, which creates and returns a new validation manager object.
  91. func Validator() *gvalid.Validator {
  92. return gvalid.New()
  93. }