diff --git a/.example/database/gdb/mysql/config.toml b/.example/database/gdb/mysql/config.toml index d63c06afc..af15452d4 100644 --- a/.example/database/gdb/mysql/config.toml +++ b/.example/database/gdb/mysql/config.toml @@ -1,8 +1,9 @@ # MySQL数据库配置 [database] -# debug = true - link = "mysql:root:12345678@tcp(127.0.0.1:3306)/test?parseTime=true&loc=Local" + debug = true + link = "mysql:root:12345678@tcp(127.0.0.1:3306)/test?parseTime=true&loc=Local" + MaxOpen = 100 #[database] # [[database.default]] diff --git a/database/gdb/gdb_core_config.go b/database/gdb/gdb_core_config.go index 9f3b2e52d..9bee4bde3 100644 --- a/database/gdb/gdb_core_config.go +++ b/database/gdb/gdb_core_config.go @@ -39,10 +39,10 @@ type ConfigNode struct { DryRun bool // (Optional) Dry run, which does SELECT but no INSERT/UPDATE/DELETE statements. Weight int // (Optional) Weight for load balance calculating, it's useless if there's just one node. Charset string // (Optional, "utf8mb4" in default) Custom charset when operating on database. - LinkInfo string // (Optional) Custom link information, when it is used, configuration Host/Port/User/Pass/Name are ignored. - MaxIdleConnCount int // (Optional) Max idle connection configuration for underlying connection pool. - MaxOpenConnCount int // (Optional) Max open connection configuration for underlying connection pool. - MaxConnLifetime time.Duration // (Optional) Max connection TTL configuration for underlying connection pool. + LinkInfo string `json:"link"` // (Optional) Custom link information, when it is used, configuration Host/Port/User/Pass/Name are ignored. + MaxIdleConnCount int `json:"maxidle"` // (Optional) Max idle connection configuration for underlying connection pool. + MaxOpenConnCount int `json:"maxopen"` // (Optional) Max open connection configuration for underlying connection pool. + MaxConnLifetime time.Duration `json:"maxlifetime"` // (Optional) Max connection TTL configuration for underlying connection pool. } // configs is internal used configuration object. diff --git a/frame/gins/gins_database.go b/frame/gins/gins_database.go index 92842b178..1a37ea4a1 100644 --- a/frame/gins/gins_database.go +++ b/frame/gins/gins_database.go @@ -8,6 +8,7 @@ package gins import ( "fmt" + "github.com/gogf/gf/internal/intlog" "github.com/gogf/gf/text/gstr" "github.com/gogf/gf/util/gutil" @@ -58,6 +59,7 @@ func Database(name ...string) gdb.DB { } } if len(cg) > 0 { + intlog.Printf("%s, %#v", group, cg) gdb.SetConfigGroup(group, cg) } } @@ -69,6 +71,7 @@ func Database(name ...string) gdb.DB { cg = append(cg, *node) } if len(cg) > 0 { + intlog.Printf("%s, %#v", gdb.DEFAULT_GROUP_NAME, cg) gdb.SetConfigGroup(gdb.DEFAULT_GROUP_NAME, cg) } } diff --git a/i18n/gi18n/gi18n_manager.go b/i18n/gi18n/gi18n_manager.go index 8311836f4..745632877 100644 --- a/i18n/gi18n/gi18n_manager.go +++ b/i18n/gi18n/gi18n_manager.go @@ -68,7 +68,7 @@ func New(options ...Options) *Manager { gregex.Quote(opts.Delimiters[1]), ), } - intlog.Printf(`New: %+v`, m) + intlog.Printf(`New: %#v`, m) return m } diff --git a/util/gconv/gconv_struct.go b/util/gconv/gconv_struct.go index 1c613130c..a3976c1e5 100644 --- a/util/gconv/gconv_struct.go +++ b/util/gconv/gconv_struct.go @@ -50,11 +50,13 @@ func Struct(params interface{}, pointer interface{}, mapping ...map[string]strin err = gerror.NewfSkip(1, "%v", e) } }() + // paramsMap is the map[string]interface{} type variable for params. paramsMap := Map(params) if paramsMap == nil { return fmt.Errorf("invalid params: %v", params) } + // Using reflect to do the converting, // it also supports type of reflect.Value for (always in internal usage). elem, ok := pointer.(reflect.Value) @@ -86,7 +88,8 @@ func Struct(params interface{}, pointer interface{}, mapping ...map[string]strin } } // It only performs one converting to the same attribute. - // doneMap is used to check repeated converting, its key is the attribute name of the struct. + // doneMap is used to check repeated converting, its key is the real attribute name + // of the struct. doneMap := make(map[string]struct{}) // It first checks the passed mapping rules. if len(mapping) > 0 && len(mapping[0]) > 0 { @@ -100,26 +103,13 @@ func Struct(params interface{}, pointer interface{}, mapping ...map[string]strin } } } - // It secondly checks the tags of attributes. - tagMap := structs.TagMapName(pointer, structTagPriority, true) - for tagK, tagV := range tagMap { - // tagV is the the attribute name of the struct. - if _, ok := doneMap[tagV]; ok { - continue - } - if v, ok := paramsMap[tagK]; ok { - doneMap[tagV] = struct{}{} - if err := bindVarToStructAttr(elem, tagV, v); err != nil { - return err - } - } - } - // It finally do the converting with default rules. // The key of the map is the attribute name of the struct, // and the value is its replaced name for later comparison to improve performance. - attrMap := make(map[string]string) - elemType := elem.Type() - tempName := "" + var ( + attrMap = make(map[string]string) + elemType = elem.Type() + tempName = "" + ) for i := 0; i < elem.NumField(); i++ { // Only do converting to public attributes. if !utils.IsLetterUpper(elemType.Field(i).Name[0]) { @@ -131,12 +121,27 @@ func Struct(params interface{}, pointer interface{}, mapping ...map[string]strin if len(attrMap) == 0 { return nil } - var attrName, checkName string + var ( + attrName string + checkName string + tagMap = structs.TagMapName(pointer, structTagPriority, true) + ) for mapK, mapV := range paramsMap { attrName = "" checkName = replaceCharReg.ReplaceAllString(mapK, "") // Loop to find the matched attribute name with or without // string cases and chars like '-'/'_'/'.'/' '. + + // Matching the parameters to struct tag names. + // The is the attribute name of the struct. + for tagK, tagV := range tagMap { + if strings.EqualFold(checkName, tagK) { + attrName = tagV + break + } + } + + // Matching the parameters to struct attributes. for attrK, attrV := range attrMap { // Eg: // UserName eq user_name @@ -148,19 +153,15 @@ func Struct(params interface{}, pointer interface{}, mapping ...map[string]strin break } } - // If the attribute name is already checked converting, then skip it. - if attrName != "" { - if _, ok := doneMap[attrName]; ok { - continue - } - if _, ok := tagMap[attrName]; ok { - continue - } - } + // No matching, give up this attribute converting. if attrName == "" { continue } + // If the attribute name is already checked converting, then skip it. + if _, ok := doneMap[attrName]; ok { + continue + } // Mark it done. doneMap[attrName] = struct{}{} if err := bindVarToStructAttr(elem, attrName, mapV); err != nil {