g_object.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Copyright 2018 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/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. )
  20. // Client is a convenience function, that creates and returns a new HTTP client.
  21. func Client() *ghttp.Client {
  22. return ghttp.NewClient()
  23. }
  24. // Server returns an instance of http server with specified name.
  25. func Server(name ...interface{}) *ghttp.Server {
  26. return gins.Server(name...)
  27. }
  28. // TCPServer returns an instance of tcp server with specified name.
  29. func TCPServer(name ...interface{}) *gtcp.Server {
  30. return gtcp.GetServer(name...)
  31. }
  32. // UDPServer returns an instance of udp server with specified name.
  33. func UDPServer(name ...interface{}) *gudp.Server {
  34. return gudp.GetServer(name...)
  35. }
  36. // View returns an instance of template engine object with specified name.
  37. func View(name ...string) *gview.View {
  38. return gins.View(name...)
  39. }
  40. // Config returns an instance of config object with specified name.
  41. func Config(name ...string) *gcfg.Config {
  42. return gins.Config(name...)
  43. }
  44. // Cfg is alias of Config.
  45. // See Config.
  46. func Cfg(name ...string) *gcfg.Config {
  47. return Config(name...)
  48. }
  49. // Resource returns an instance of Resource.
  50. // The parameter <name> is the name for the instance.
  51. func Resource(name ...string) *gres.Resource {
  52. return gins.Resource(name...)
  53. }
  54. // I18n returns an instance of gi18n.Manager.
  55. // The parameter <name> is the name for the instance.
  56. func I18n(name ...string) *gi18n.Manager {
  57. return gins.I18n(name...)
  58. }
  59. // Res is alias of Resource.
  60. // See Resource.
  61. func Res(name ...string) *gres.Resource {
  62. return Resource(name...)
  63. }
  64. // Log returns an instance of glog.Logger.
  65. // The parameter <name> is the name for the instance.
  66. func Log(name ...string) *glog.Logger {
  67. return gins.Log(name...)
  68. }
  69. // Database returns an instance of database ORM object with specified configuration group name.
  70. func Database(name ...string) gdb.DB {
  71. return gins.Database(name...)
  72. }
  73. // DB is alias of Database.
  74. // See Database.
  75. func DB(name ...string) gdb.DB {
  76. return gins.Database(name...)
  77. }
  78. // Table is alias of Model.
  79. func Table(tables string, db ...string) *gdb.Model {
  80. return DB(db...).Table(tables)
  81. }
  82. // Model creates and returns a model from specified database or default database configuration.
  83. // The optional parameter <db> specifies the configuration group name of the database,
  84. // which is "default" in default.
  85. func Model(tables string, db ...string) *gdb.Model {
  86. return DB(db...).Model(tables)
  87. }
  88. // Redis returns an instance of redis client with specified configuration group name.
  89. func Redis(name ...string) *gredis.Redis {
  90. return gins.Redis(name...)
  91. }