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