diff --git a/TODO b/TODO.MD similarity index 53% rename from TODO rename to TODO.MD index ae76a2dcc..a45402e0c 100644 --- a/TODO +++ b/TODO.MD @@ -1,52 +1,51 @@ -ON THE WAY: -orm增加更多数据库支持; -增加对于数据表Model的封装; -更多数据库的ORM功能支持; -考虑gdb对象管理增加二级连接池特性,提高New&Close性能; -增加图形验证码支持,至少支持数字和英文字母; -增加热编译工具,提高开发环境的开发/测试效率(媲美PHP开发效率); -增加可选择性的orm tag特性,用以数据表记录与struct对象转换的键名属性映射; -ghttp.Response增加输出内容后自动退出当前请求机制,不需要用户手动return,参考beego如何实现; -Cookie&Session数据池化处理; -ghttp.Client增加proxy特性; -gtime增加对时区转换的封装,并简化失去转换时对类似+80500时区的支持; -orm增加sqlite对Save方法的支持(去掉触发器语句); -ghttp.Server增加Ip访问控制功能(DenyIps&AllowIps); -ghttp路由功能增加分组路由特性; -ghttp增加返回数据压缩机制; -gview中的template标签失效问题; -gfile文件stat信息使用gfsnotify进行缓存更新改进; -ghttp.Server增加proxy功能特性,本地proxy和远程proxy,本地即将路由规则映射;远程即反向代理; -gjson对大json数据的解析效率问题; -ghttp增加route name特性,并同时支持backend和template(提供内置函数)引用,可以通过RedirectRoute方法给定route name和路由参数跳转到指定的路由地址上; -ghttp.Client自动Close机制; -gvalid校验支持当第一个规则失败后便不再校验后续的规则,最好做成链式操作; -检查ghttp.Server超时问题; -gvalid增加支持对[]rune的长度校验(一个中文占3个字节); -ghttp.Request增加对输入参数的自动HtmlEncode机制; -常量命名风格根据golint进行修改; -开放rwmutex包,并将gjson的互斥锁使用自定义的mutex替换; -文档完善: - gconv struct tag、 - 控制器及执行对象注册的Init&Shut方法、 - ghttp.Response&ServeFile、gfcache、gproc shell执行、 - ghttp Server&Client basic auth、 - glog分类&日志等级&链式操作、gdb debug自动输出调试信息、gmlock内存锁、 -服务注册域名增加对泛域名的支持; -服务注册时判断方法定义满足规范时才执行绑定,否则提示WARN信息; -Cookie设置中文失效问题; -ghttp hook回调使用方式在注册路由比较多的时候,优先级可能使得开发者混乱,考虑方式便于管理; -使用gconv将slice映射到struct属性上,例如redis hscan的结果集; -项目参考: - https://github.com/namreg/godown - https://github.com/Masterminds/sprig -gform参考 https://gohouse.github.io/gorose/dist/index.html 进行改进 -完善配置管理章节,说明默认的配置文件更改方式; -完善gform配置管理说明,g.DB/Database和gdb.New的区别; +# ON THE WAY +1. orm增加更多数据库支持; +1. 增加对于数据表Model的封装; +1. 更多数据库的ORM功能支持; +1. 考虑gdb对象管理增加二级连接池特性,提高New&Close性能; +1. 增加图形验证码支持,至少支持数字和英文字母; +1. 增加热编译工具,提高开发环境的开发/测试效率(媲美PHP开发效率); +1. 增加可选择性的orm tag特性,用以数据表记录与struct对象转换的键名属性映射; +1. ghttp.Response增加输出内容后自动退出当前请求机制,不需要用户手动return,参考beego如何实现; +1. Cookie&Session数据池化处理; +1. ghttp.Client增加proxy特性; +1. gtime增加对时区转换的封装,并简化失去转换时对类似+80500时区的支持; +1. orm增加sqlite对Save方法的支持(去掉触发器语句); +1. ghttp.Server增加Ip访问控制功能(DenyIps&AllowIps); +1. ghttp路由功能增加分组路由特性; +1. ghttp增加返回数据压缩机制; +1. gview中的template标签失效问题; +1. gfile文件stat信息使用gfsnotify进行缓存更新改进; +1. ghttp.Server增加proxy功能特性,本地proxy和远程proxy,本地即将路由规则映射;远程即反向代理; +1. gjson对大json数据的解析效率问题; +1. ghttp增加route name特性,并同时支持backend和template(提供内置函数)引用,可以通过RedirectRoute方法给定route name和路由参数跳转到指定的路由地址上; +1. ghttp.Client自动Close机制; +1. gvalid校验支持当第一个规则失败后便不再校验后续的规则,最好做成链式操作; +1. 检查ghttp.Server超时问题; +1. gvalid增加支持对[]rune的长度校验(一个中文占3个字节); +1. ghttp.Request增加对输入参数的自动HtmlEncode机制; +1. 常量命名风格根据golint进行修改; +1. 开放rwmutex包,并将gjson的互斥锁使用自定义的mutex替换; +1. 文档完善: + - gconv struct tag、 + - 控制器及执行对象注册的Init&Shut方法、 + - ghttp.Response&ServeFile、gfcache、gproc shell执行、 + - ghttp Server&Client basic auth、 + - glog分类&日志等级&链式操作、gdb debug自动输出调试信息、gmlock内存锁、 +1. 服务注册域名增加对泛域名的支持; +1. Cookie设置中文失效问题; +1. ghttp hook回调使用方式在注册路由比较多的时候,优先级可能使得开发者混乱,考虑方式便于管理; +1. 使用gconv将slice映射到struct属性上,例如redis hscan的结果集; +1. 项目参考: + - https://github.com/namreg/godown + - https://github.com/Masterminds/sprig +1. gform参考 https://gohouse.github.io/gorose/dist/index.html 进行改进 -DONE: + + +# DONE 1. gconv完善针对不同类型的判断,例如:尽量减少sprintf("%v", xxx)来执行string类型的转换; 2. ghttp.Server请求执行中增加服务退出的方法,不再执行后续操作; 3. ghttp.Response对象完善并改进数据返回方法(Write/WriteString); @@ -89,4 +88,9 @@ DONE: 40. ghttp.Server的Cookie及Session锁机制优化(去掉map锁机制); 41. 解决glog串日志情况; 42. glog增加对日志文件名称的生成规则设定,支持时间格式规则; -43. ghttp日志增加客户端IP信息; \ No newline at end of file +43. ghttp日志增加客户端IP信息; +44. 完善gform配置管理说明,g.DB/Database和gdb.New的区别; +1. 完善配置管理章节,说明默认的配置文件更改方式; +1. 服务注册时判断方法定义满足规范时才执行绑定,否则提示WARN信息; + + diff --git a/g/database/gdb/gdb.go b/g/database/gdb/gdb.go index a01ba4cd0..88a4e6cca 100644 --- a/g/database/gdb/gdb.go +++ b/g/database/gdb/gdb.go @@ -9,17 +9,17 @@ package gdb import ( - "fmt" - "time" - "errors" "database/sql" - "gitee.com/johng/gf/g/container/gmap" - "gitee.com/johng/gf/g/container/gring" - "gitee.com/johng/gf/g/container/gtype" - "gitee.com/johng/gf/g/os/gcache" - "gitee.com/johng/gf/g/util/grand" - _ "gitee.com/johng/gf/third/github.com/go-sql-driver/mysql" - "gitee.com/johng/gf/g/container/gvar" + "errors" + "fmt" + "gitee.com/johng/gf/g/container/gmap" + "gitee.com/johng/gf/g/container/gring" + "gitee.com/johng/gf/g/container/gtype" + "gitee.com/johng/gf/g/container/gvar" + "gitee.com/johng/gf/g/os/gcache" + "gitee.com/johng/gf/g/util/grand" + _ "gitee.com/johng/gf/third/github.com/go-sql-driver/mysql" + "time" ) const ( @@ -122,18 +122,17 @@ type Map = map[string]interface{} // 关联数组列表(索引从0开始的数组),绑定多条记录(使用别名) type List = []Map -var driverLink map[string]interface{} - -// 数据库查询缓存对象map,使用数据库连接名称作为键名,键值为查询缓存对象 -var dbCaches = gmap.NewStringInterfaceMap() - - +var ( + // 支持的数据库类型map + driverMap = make(map[string]interface{}) + // 数据库查询缓存对象map,使用数据库连接名称作为键名,键值为查询缓存对象 + dbCaches = gmap.NewStringInterfaceMap() +) func init() { - driverLink = make(map[string]interface{}) - driverLink["mysql"] = linkMysql - driverLink["oracle"] = linkOracle - driverLink["sqllite"] = linkSqlite - driverLink["pgsql"] = linkPgsql + driverMap["mysql"] = linkMysql + driverMap["oracle"] = linkOracle + driverMap["sqllite"] = linkSqlite + driverMap["pgsql"] = linkPgsql } // 使用默认/指定分组配置进行连接,数据库集群配置项:default @@ -240,7 +239,7 @@ func getConfigNodeByPriority(cg ConfigGroup) *ConfigNode { // 根据配置的数据库;类型获得Link接口对象 func getLinkByType(dbType string) (Link, error) { - if dblink, ok := driverLink[dbType]; ok == false { + if dblink, ok := driverMap[dbType]; ok == false { return nil, errors.New(fmt.Sprintf("unsupported db type '%s'", dbType)) } else { return dblink.(Link), nil diff --git a/g/frame/gins/gins.go b/g/frame/gins/gins.go index 6404848e6..2325bb396 100644 --- a/g/frame/gins/gins.go +++ b/g/frame/gins/gins.go @@ -74,7 +74,7 @@ func View(name...string) *gview.View { return instances.GetOrSetFuncLock(key, func() interface{} { path := gcmd.Option.Get("gf.viewpath") if path == "" { - path = genv.Get("gf.viewpath") + path = genv.Get("GF_VIEWPATH") if path == "" { path = gfile.SelfDir() } @@ -101,7 +101,7 @@ func Config(file...string) *gcfg.Config { func() interface{} { path := gcmd.Option.Get("gf.cfgpath") if path == "" { - path = genv.Get("gf.cfgpath") + path = genv.Get("GF_CFGPATH") if path == "" { path = gfile.SelfDir() } @@ -161,6 +161,9 @@ func Database(name...string) *gdb.Db { if value, ok := nodem["priority"]; ok { node.Priority = gconv.Int(value) } + if value, ok := nodem["linkinfo"]; ok { + node.Linkinfo = gconv.String(value) + } if value, ok := nodem["max-idle"]; ok { node.MaxIdleConnCount = gconv.Int(value) } diff --git a/g/g_logger.go b/g/g_logger.go index ac9f1d6cf..50f71c478 100644 --- a/g/g_logger.go +++ b/g/g_logger.go @@ -6,7 +6,21 @@ package g -import "gitee.com/johng/gf/g/os/glog" +import ( + "gitee.com/johng/gf/g/os/gcmd" + "gitee.com/johng/gf/g/os/genv" + "gitee.com/johng/gf/g/os/glog" + "gitee.com/johng/gf/g/util/gconv" +) + +func init() { + if v := genv.Get("GF_DEBUG"); v != "" { + SetDebug(gconv.Bool(v)) + } + if v := gcmd.Option.Get("gf.debug"); v != "" { + SetDebug(gconv.Bool(v)) + } +} // 是否显示调试信息 func SetDebug(debug bool) { diff --git a/g/net/ghttp/ghttp_server.go b/g/net/ghttp/ghttp_server.go index 954864822..1ad12d116 100644 --- a/g/net/ghttp/ghttp_server.go +++ b/g/net/ghttp/ghttp_server.go @@ -296,7 +296,7 @@ func (s *Server) GetRouteMap() string { buf := bytes.NewBuffer(nil) table := tablewriter.NewWriter(buf) - table.SetHeader([]string{"SERVER", "ADDRESS", "DOMAIN", "METHOD", "ROUTE", "HANDLER", "HOOK"}) + table.SetHeader([]string{"SERVER", "ADDRESS", "DOMAIN", "METHOD", "P", "ROUTE", "HANDLER", "HOOK"}) table.SetRowLine(true) table.SetBorder(false) table.SetCenterSeparator("|") @@ -333,16 +333,17 @@ func (s *Server) GetRouteMap() string { addr += ",tls" + s.config.HTTPSAddr } for _, a := range m { - data := make([]string, 7) + data := make([]string, 8) for _, v := range a.Slice() { item := v.(*tableItem) data[0] = s.name data[1] = addr data[2] = item.domain data[3] = item.method - data[4] = item.route - data[5] = item.handler - data[6] = item.hook + data[4] = gconv.String(len(strings.Split(item.route, "/")) - 1) + data[5] = item.route + data[6] = item.handler + data[7] = item.hook table.Append(data) } }