-
Notifications
You must be signed in to change notification settings - Fork 0
/
g_object.go
108 lines (90 loc) · 3.13 KB
/
g_object.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package g
import (
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/database/gredis"
"github.com/gogf/gf/v2/frame/gins"
"github.com/gogf/gf/v2/i18n/gi18n"
"github.com/gogf/gf/v2/net/gclient"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/net/gudp"
"github.com/gogf/gf/v2/os/gcfg"
"github.com/gogf/gf/v2/os/glog"
"github.com/gogf/gf/v2/os/gres"
"github.com/gogf/gf/v2/os/gview"
"github.com/gogf/gf/v2/util/gvalid"
)
// Client is a convenience function, which creates and returns a new HTTP client.
func Client() *gclient.Client {
return gclient.New()
}
// Server returns an instance of http server with specified name.
func Server(name ...interface{}) *ghttp.Server {
return gins.Server(name...)
}
// TCPServer returns an instance of tcp server with specified name.
func TCPServer(name ...interface{}) *gtcp.Server {
return gtcp.GetServer(name...)
}
// UDPServer returns an instance of udp server with specified name.
func UDPServer(name ...interface{}) *gudp.Server {
return gudp.GetServer(name...)
}
// View returns an instance of template engine object with specified name.
func View(name ...string) *gview.View {
return gins.View(name...)
}
// Config returns an instance of config object with specified name.
func Config(name ...string) *gcfg.Config {
return gins.Config(name...)
}
// Cfg is alias of Config.
// See Config.
func Cfg(name ...string) *gcfg.Config {
return Config(name...)
}
// Resource returns an instance of Resource.
// The parameter `name` is the name for the instance.
func Resource(name ...string) *gres.Resource {
return gins.Resource(name...)
}
// I18n returns an instance of gi18n.Manager.
// The parameter `name` is the name for the instance.
func I18n(name ...string) *gi18n.Manager {
return gins.I18n(name...)
}
// Res is alias of Resource.
// See Resource.
func Res(name ...string) *gres.Resource {
return Resource(name...)
}
// Log returns an instance of glog.Logger.
// The parameter `name` is the name for the instance.
func Log(name ...string) *glog.Logger {
return gins.Log(name...)
}
// DB returns an instance of database ORM object with specified configuration group name.
func DB(name ...string) gdb.DB {
return gins.Database(name...)
}
// Model creates and returns a model based on configuration of default database group.
func Model(tableNameOrStruct ...interface{}) *gdb.Model {
return DB().Model(tableNameOrStruct...)
}
// ModelRaw creates and returns a model based on a raw sql not a table.
func ModelRaw(rawSql string, args ...interface{}) *gdb.Model {
return DB().Raw(rawSql, args...)
}
// Redis returns an instance of redis client with specified configuration group name.
func Redis(name ...string) *gredis.Redis {
return gins.Redis(name...)
}
// Validator is a convenience function, which creates and returns a new validation manager object.
func Validator() *gvalid.Validator {
return gvalid.New()
}