GF为使用者提供了几种配置:
GF工具
- 工具配置:工具配置指的是
GoFrame
框架提供的开发工具的配置,仅用于项目开发使用。 - 业务配置:业务配置指的是业务项目运行所需的配置,用于业务项目部署运行,部署不同的环境,业务配置往往不同。
全局配置对象
GF为使用者提供了一个可以直接获取项目配置文件的方法g.Cfg()
,通过g.Cfg()
将会自动读取manifest/config
目录下的配置文件的内容,不支持热加载.
其他全局对象
- 常用数据类型别名
type (
Var = gvar.Var // 通用变量,定义的是结构体,支持并发安全访问.
Ctx = context.Context // 上下文别名
)
type (
Map = map[string]interface{}
MapAnyAny = map[interface{}]interface{}
MapAnyStr = map[interface{}]string
MapAnyInt = map[interface{}]int
MapStrAny = map[string]interface{}
MapStrStr = map[string]string
MapStrInt = map[string]int
MapIntAny = map[int]interface{}
MapIntStr = map[int]string
MapIntInt = map[int]int
MapAnyBool = map[interface{}]bool
MapStrBool = map[string]bool
MapIntBool = map[int]bool
)
type (
List = []Map
ListAnyAny = []MapAnyAny
ListAnyStr = []MapAnyStr
ListAnyInt = []MapAnyInt
ListStrAny = []MapStrAny
ListStrStr = []MapStrStr
ListStrInt = []MapStrInt
ListIntAny = []MapIntAny
ListIntStr = []MapIntStr
ListIntInt = []MapIntInt
ListAnyBool = []MapAnyBool
ListStrBool = []MapStrBool
ListIntBool = []MapIntBool
)
type (
Slice = []interface{}
SliceAny = []interface{}
SliceStr = []string
SliceInt = []int
)
type (
Array = []interface{}
ArrayAny = []interface{}
ArrayStr = []string
ArrayInt = []int
)
HTTP
客户端对象
g.Client() // 创建一个新的`HTTP`客户端对象。
Validator
校验对象
g.Validator() // 创建一个新的数据校验对象。
- (单例) 配置管理对象
g.Cfg()
- (单例) 日志管理对象
g.Log() // 该单例对象将会自动读取默认配置文件中的`logger`配置项,并只会初始化一次日志对象。
- (单例) 模板引擎对象
g.View() // 该单例对象将会自动读取默认配置文件中的`viewer`配置项,并只会初始化一次模板引擎对象。内部采用了`懒初始化`设计,获取模板引擎对象时只是创建了一个轻量的模板管理对象,只有当解析模板文件时才会真正初始化。
- (单例)
WEB Server
g.Server() // 该单例对象将会自动读取默认配置文件中的`server`配置项,并只会初始化一次`Server`对象。
- (单例)
TCP Server
g.TcpServer() //
- (单例)
UDP Server
g.UdpServer() //
- (单例) 数据库
ORM
对象
g.DB() // 该单例对象将会自动读取默认配置文件中的`database`配置项,并只会初始化一次`DB`对象。
- (单例)
Redis
客户端对象
g.Redis() // 该单例对象将会自动读取默认配置文件中的`redis`配置项,并只会初始化一次`Redis`对象。
- (单例) 资源管理对象
g.Res()
- (单例) 国际化管理对象
g.I18n()