fix database configuration parsing for package gins

This commit is contained in:
John Guo 2022-06-20 11:14:13 +08:00
parent 1e8237446e
commit bb5cd3e224

View File

@ -16,6 +16,8 @@ import (
"github.com/gogf/gf/v2/internal/consts"
"github.com/gogf/gf/v2/internal/intlog"
"github.com/gogf/gf/v2/os/gcfg"
"github.com/gogf/gf/v2/text/gregex"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gconv"
"github.com/gogf/gf/v2/util/gutil"
)
@ -171,5 +173,13 @@ func parseDBConfigNode(value interface{}) *gdb.ConfigNode {
if _, v := gutil.MapPossibleItemByKey(nodeMap, "Link"); v != nil {
node.Link = gconv.String(v)
}
// Parse `Link` configuration syntax.
if node.Link != "" && node.Type == "" {
match, _ := gregex.MatchString(`([a-z]+):(.+)`, node.Link)
if len(match) == 3 {
node.Type = gstr.Trim(match[1])
node.Link = gstr.Trim(match[2])
}
}
return node
}