- 全局对象
- 数据类型
- 常用对象
- Debug模式
全局对象
GF框架封装了一些常用的数据类型以及对象,可以直接通过g.*方便获取。
g是一个强耦合的模块,目的是为开发者在对频繁使用的对象调用时提供便利。
使用方式:
import "github.com/gogf/gf/g"
数据类型
// 泛型type Var = gvar.Var// 常用Map类型type Map = map[string]interface{}type MapAnyAny = map[interface{}]interface{}type MapAnyStr = map[interface{}]stringtype MapAnyInt = map[interface{}]inttype MapStrAny = map[string]interface{}type MapStrStr = map[string]stringtype MapStrInt = map[string]inttype MapIntAny = map[int]interface{}type MapIntStr = map[int]stringtype MapIntInt = map[int]int// 常用Slice Map类型type List = []Maptype ListAnyStr = []map[interface{}]stringtype ListAnyInt = []map[interface{}]inttype ListStrAny = []map[string]interface{}type ListStrStr = []map[string]stringtype ListStrInt = []map[string]inttype ListIntAny = []map[int]interface{}type ListIntStr = []map[int]stringtype ListIntInt = []map[int]int// 常用Slice类型type Slice = []interface{}type SliceAny = []interface{}type SliceStr = []stringtype SliceInt = []int// 常用Slice类型(别名)type Array = []interface{}type ArrayAny = []interface{}type ArrayStr = []stringtype ArrayInt = []int
常用对象
- (单例) 配置管理对象
func Config(name...string) *gcfg.Config
- (单例) 模板引擎对象
func View(name ...string) *gview.View
- (单例) WEB Server
func Server(name ...interface{}) *ghttp.Server
- (单例) TCP Server
func TcpServer(name ...interface{}) *gtcp.Server
- (单例) UDP Server
func UdpServer(name ...interface{}) *gudp.Server
- (单例) 数据库ORM对象
func DB(name ...string) *gdb.Db
- (单例) Redis客户端对象
func Redis(name ...string) *gredis.Redis
Debug模式
默认情况下,gf框架的各个模块都会开启调试模式,输出一些调试信息,有助于开发者在开发环境中调试定位问题。但是程序正式部署到生产环境之后,这些调试信息往往没有那么必要,并且过多的调试信息也容易在查看重要业务日志的时候影响视觉。因此我们可以通过一些方式关闭掉调试信息。
- (推荐) 使用
g.SetDebug(false)方法设置; - 修改命令行启动参数 -
gf.glog.debug=false; - 修改指定的环境变量 -
GF_GLOG_DEBUG=false;
