2 Star 0 Fork 4

Ryan / MysqlGo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
field.go 1.00 KB
AI 代码解读
一键复制 编辑 原始数据 按行查看 历史
package mysqlgo
import (
"reflect"
)
type field struct {
names []string
values []interface{}
}
func (f *field) parseData(data interface{}) {
keys, value := f.parseInterface(data)
f.names, f.values = keys, value
}
func (f *field) parseDatas(datas ...interface{}) ([][]interface{}, error) {
if len(datas) == 0 {
return nil, GetError(DataNull)
}
data := datas[0]
var values [][]interface{}
keys, value := f.parseInterface(data)
f.names = keys
values = append(values, value)
for i := 1 ; i < len(datas); i++ {
if !reflect.DeepEqual(data, datas[i]) {
return nil, GetError(TypeError)
}
_, value := f.parseInterface(datas[i])
values = append(values, value)
}
return values, nil
}
func (f *field) parseInterface(data interface{}) (keys []string, values []interface{}) {
getType := reflect.TypeOf(data)
getValue := reflect.ValueOf(data)
for i := 0; i < getType.NumField(); i ++ {
keys = append(keys, getType.Field(i).Name)
values = append(values, getValue.Field(i).Interface())
}
return
}
Go
1
https://gitee.com/ironCoffers/MysqlGo.git
git@gitee.com:ironCoffers/MysqlGo.git
ironCoffers
MysqlGo
MysqlGo
master

搜索帮助