增加获取默认值方法

This commit is contained in:
白茶清欢 2022-07-04 12:30:53 +08:00
parent a94d99cd14
commit d52af7e3f4

View File

@ -7,7 +7,10 @@
// Date : 2022-07-04 11:45 // Date : 2022-07-04 11:45
package util package util
import "github.com/Jeffail/gabs" import (
"github.com/Jeffail/gabs"
"github.com/pkg/errors"
)
// MapRule 映射规则 // MapRule 映射规则
// //
@ -61,5 +64,54 @@ func (f *filter) Deal() ([]byte, error) {
// //
// Date : 12:25 2022/7/4 // Date : 12:25 2022/7/4
func (f *filter) getDefaultValue(dataType string, defaultValue string) (interface{}, error) { func (f *filter) getDefaultValue(dataType string, defaultValue string) (interface{}, error) {
return nil, nil switch dataType {
case "int8":
fallthrough
case "int16":
fallthrough
case "int32":
fallthrough
case "int64":
fallthrough
case "int":
var (
err error
val int64
)
err = ConvertAssign(&val, defaultValue)
return val, err
case "uint8":
fallthrough
case "uint16":
fallthrough
case "uint32":
fallthrough
case "uint64":
fallthrough
case "uint":
var (
err error
val uint64
)
err = ConvertAssign(&val, defaultValue)
return val, err
case "bool":
var (
err error
val bool
)
err = ConvertAssign(&val, defaultValue)
return val, err
case "float32":
fallthrough
case "float64":
var (
err error
val float64
)
err = ConvertAssign(&val, defaultValue)
return val, err
default:
return nil, errors.New(dataType + " is not support!")
}
} }