g_object.go 3.1 KB

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