全局对象

    常用数据类型别名。

    1. // 泛型
    2. type Var = gvar.Var
    3. // 常用Map类型
    4. type Map = map[string]interface{}
    5. type MapAnyAny = map[interface{}]interface{}
    6. type MapAnyStr = map[interface{}]string
    7. type MapAnyInt = map[interface{}]int
    8. type MapStrAny = map[string]interface{}
    9. type MapStrStr = map[string]string
    10. type MapStrInt = map[string]int
    11. type MapIntAny = map[int]interface{}
    12. type MapIntStr = map[int]string
    13. type MapIntInt = map[int]int
    14. type List = []Map
    15. type ListAnyInt = []map[interface{}]int
    16. type ListStrAny = []map[string]interface{}
    17. type ListStrStr = []map[string]string
    18. type ListStrInt = []map[string]int
    19. type ListIntAny = []map[int]interface{}
    20. type ListIntStr = []map[int]string
    21. type ListIntInt = []map[int]int
    22. // 常用Slice类型
    23. type Slice = []interface{}
    24. type SliceAny = []interface{}
    25. type SliceStr = []string
    26. type SliceInt = []int
    27. // 常用Slice类型(别名)
    28. type ArrayAny = []interface{}
    29. type ArrayStr = []string
    30. type ArrayInt = []int

    常用对象

    1. (单例) 配置管理对象
        别名:
        1. func Cfg(name ...string) *gcfg.Config
      1. (单例) 日志管理对象
      2. (单例) 模板引擎对象
        1. func View(name ...string) *gview.View
      3. (单例) WEB Server
        1. func Server(name ...interface{}) *ghttp.Server
      4. (单例) TCP Server
        1. func TcpServer(name ...interface{}) *gtcp.Server
      5. (单例) UDP Server
      6. (单例) 数据库ORM对象
        1. func DB(name ...string) *gdb.Db
      7. (单例) Redis客户端对象
        1. func Redis(name ...string) *gredis.Redis
      8. (单例) 资源管理对象
        1. func Resource(name ...string) *gres.Resource
        别名:
      9. (单例) 国际化管理对象
        1. func I18n(name ...string) *gi18n.Manager

      Debug模式

      默认情况下,gf框架的各个模块都会开启调试模式,输出一些调试信息,有助于开发者在开发环境中调试定位问题。但是程序正式部署到生产环境之后,这些调试信息往往没有那么必要,并且过多的调试信息也容易在查看重要业务日志的时候影响视觉。因此我们可以通过一些方式关闭掉调试信息。

      1. (推荐) 使用 g.SetDebug(false) 方法设置;
      2. 修改命令行启动参数 - gf.glog.debug=false
      3. 修改指定的环境变量 - GF_GLOG_DEBUG=false