本文整理匯總了Golang中github.com/eaciit/toolkit.Serde函數的典型用法代碼示例。如果您正苦於以下問題:Golang Serde函數的具體用法?Golang Serde怎麽用?Golang Serde使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Serde函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Fetch
func (c *Cursor) Fetch(m interface{}, n int, closeWhenDone bool) error {
var source []toolkit.M
var lower, upper int
lower = c.currentIndex
upper = lower + n
if n == 0 {
if c.where == nil {
upper = len(c.q.data)
} else {
upper = len(c.indexes)
}
} else if n == 1 {
upper = lower + 1
} else {
upper = lower + n
if c.where == nil {
if upper > len(c.q.data) {
upper = len(c.q.data)
}
} else {
if upper > len(c.indexes) {
upper = len(c.indexes)
}
}
}
if c.where == nil {
source = c.q.data[lower:upper]
} else {
for _, v := range c.indexes[lower:upper] {
/*
toolkit.Printf("Add index: %d. Source info now: %s \n", v, func() string {
var ret []string
for _, id := range source {
ret = append(ret, id.Get("_id").(string))
}
return strings.Join(ret, ",")
}())
*/
if v < len(c.q.data) {
source = append(source, c.q.data[v])
}
}
}
var e error
if n == 1 {
e = toolkit.Serde(&source[0], m, "json")
} else {
e = toolkit.Serde(&source, m, "json")
}
if e != nil {
return errorlib.Error(packageName, modCursor, "Fetch", e.Error())
}
//toolkit.Printf("Data: %s\nLower, Upper = %d, %d\nSource: %s\nResult:%s\n\n", toolkit.JsonString(c.q.data), lower, upper, toolkit.JsonString(source), toolkit.JsonString(m))
return nil
}
示例2: TestHiveExec
func TestHiveExec(t *testing.T) {
q := "select * from sample_07 limit 1;"
// x := "select * from sample_07 limit 3;"
DoSomething := func(res HiveResult) (e error) {
toolkit.Serde(res, &res.ResultObj, "json")
log.Printf("result: \n%v\n", res.ResultObj)
return
}
/*DoElse := func(res HiveResult) (e error) {
tmp := toolkit.M{}
toolkit.Serde(res, &res.ResultObj, "json")
log.Printf("limit 3: \n%v\n", tmp)
return
}*/
h.Conn.FnReceive = DoSomething
h.Conn.Open()
h.Exec(q)
/*h.Conn.Wait()
h.Conn.FnReceive = DoElse
h.Exec(x)
h.Conn.Wait()
h.Conn.Open()
h.Exec(q)
h.Conn.FnReceive = DoElse
h.Exec(x)
h.Conn.Close()
/*h.Conn.Exec = true
h.Conn.Open()
h.Conn.FnReceive = DoSomething
h.Exec(q)
h.Conn.FnReceive = DoElse
h.Exec(x)
h.Conn.Exec = false
var res []toolkit.M
e := h.Populate(q, &res)
log.Printf("res: %v\n", res)
log.Printf("e: %v\n", e)
h.Conn.Close()
}*/
/*e := h.Populate(q, &res)
log.Printf("populate res: \n%v\n", res)
log.Printf("populate e: \n%v\n", e)*/
h.Conn.Close()
}
示例3: SaveGroupConfigLdap
func (a *GroupController) SaveGroupConfigLdap(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
payload := map[string]interface{}{}
err := r.GetPayload(&payload)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
o := new(colonycore.Ldap)
o.ID = payload["Address"].(string)
o.Address = payload["Address"].(string)
o.BaseDN = payload["BaseDN"].(string)
o.FilterGroup = payload["Filter"].(string)
o.Username = payload["Username"].(string)
//o.Password = payload["Password"].(string)
err = toolkit.Serde(payload["Attribute"], &o.AttributesGroup, "json")
if err != nil {
return helper.CreateResult(false, err.Error(), "error")
}
err = colonycore.Save(o)
if err != nil {
return helper.CreateResult(false, o, err.Error())
}
return helper.CreateResult(true, o, "")
}
示例4: FindUserLdap
func (a *GroupController) FindUserLdap(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
payload := map[string]interface{}{}
err := r.GetPayload(&payload)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
addr := payload["Address"].(string)
basedn := payload["BaseDN"].(string)
filter := payload["Filter"].(string)
username := payload["Username"].(string)
password := payload["Password"].(string)
var attr []string
err = toolkit.Serde(payload["Attribute"], &attr, "json")
if err != nil {
return helper.CreateResult(false, err, "error")
}
param := toolkit.M{}
param.Set("username", username)
param.Set("password", password)
param.Set("attributes", attr)
arrm, err := acl.FindDataLdap(addr, basedn, filter, param)
if err != nil {
return helper.CreateResult(false, err, "error")
}
return helper.CreateResult(true, arrm, "success")
}
示例5: TestFindUserLdap
func (a *UserController) TestFindUserLdap(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
payload := map[string]interface{}{}
err := r.GetPayload(&payload)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
addr := toolkit.ToString(payload["Address"]) //192.168.0.200:389
basedn := toolkit.ToString(payload["BaseDN"]) //DC=eaciit,DC=local
filter := toolkit.ToString(payload["Filter"]) //(&(objectclass=person)(objectclass=organizationalPerson)(cn=*))
var attr []string
err = toolkit.Serde(payload["Attribute"], &attr, "json")
if err != nil {
return helper.CreateResult(true, err, "error")
}
param := toolkit.M{}
param.Set("username", toolkit.ToString(payload["Username"])) //Alip Sidik
param.Set("password", toolkit.ToString(payload["Password"])) //Password.1
// param.Set("attributes", []string{"cn", "givenName"})
param.Set("attributes", attr)
arrtkm, err := acl.FindDataLdap(addr, basedn, filter, param)
if err != nil {
return helper.CreateResult(true, err, "error")
}
return helper.CreateResult(true, arrtkm, "sukses")
}
示例6: InsertBulk
func (b *BaseController) InsertBulk(result []tk.M, m orm.IModel, wg *sync.WaitGroup) {
var datas []orm.IModel
for _, i := range result {
valueType := reflect.TypeOf(m).Elem()
for f := 0; f < valueType.NumField(); f++ {
field := valueType.Field(f)
bsonField := field.Tag.Get("bson")
jsonField := field.Tag.Get("json")
if jsonField != bsonField && field.Name != "RWMutex" && field.Name != "ModelBase" {
i.Set(field.Name, GetMgoValue(i, bsonField))
}
switch field.Type.Name() {
case "string":
if GetMgoValue(i, bsonField) == nil {
i.Set(field.Name, "")
}
break
case "Time":
if GetMgoValue(i, bsonField) == nil {
i.Set(field.Name, time.Time{})
} else {
i.Set(field.Name, GetMgoValue(i, bsonField).(time.Time).UTC())
}
break
default:
break
}
}
newPointer := getNewPointer(m)
e := tk.Serde(i, newPointer, "json")
datas = append(datas, newPointer)
if e != nil {
tk.Printf("\n----------- ERROR -------------- \n %v \n\n %#v \n\n %#v \n------------------------- \n", e.Error(), i, newPointer)
wg.Done()
}
}
if nil != datas {
muinsert.Lock()
for {
e := b.Ctx.InsertBulk(datas)
if e == nil {
ctn := len(result)
idx += ctn
tk.Printf("saved: %v data(s)\n", idx)
break
} else {
b.Ctx.Connection.Connect()
}
}
muinsert.Unlock()
}
wg.Done()
}
示例7: Insert
func (b *BaseController) Insert(result []tk.M, m orm.IModel, wg *sync.WaitGroup) {
// muinsert := &sync.Mutex{}
for _, i := range result {
valueType := reflect.TypeOf(m).Elem()
for f := 0; f < valueType.NumField(); f++ {
field := valueType.Field(f)
bsonField := field.Tag.Get("bson")
jsonField := field.Tag.Get("json")
if jsonField != bsonField && field.Name != "RWMutex" && field.Name != "ModelBase" {
i.Set(field.Name, GetMgoValue(i, bsonField))
}
switch field.Type.Name() {
case "string":
if GetMgoValue(i, bsonField) == nil {
i.Set(field.Name, "")
}
break
case "Time":
if GetMgoValue(i, bsonField) == nil {
i.Set(field.Name, time.Time{})
} else {
i.Set(field.Name, GetMgoValue(i, bsonField).(time.Time).UTC())
}
break
default:
break
}
}
newPointer := getNewPointer(m)
e := tk.Serde(i, newPointer, "json")
var newId int64
for index := 0; index < retry; index++ {
muinsert.Lock()
newId, e = b.Ctx.InsertOut(newPointer)
_ = newId
muinsert.Unlock()
if e == nil {
wg.Done()
break
} else {
b.Ctx.Connection.Connect()
}
}
if e != nil {
tk.Printf("\n----------- ERROR -------------- \n %v \n\n %#v \n\n %#v \n------------------------- \n", e.Error(), i, newPointer)
wg.Done()
}
}
wg.Done()
}
示例8: Fetch
func (c *Cursor) Fetch(m interface{}, n int, closeWhenDone bool) error {
end := c.start + n
if end > c.count || n == 0 {
end = c.count
}
if c.start >= c.count {
return errors.New("No more data to fetched!")
}
e := toolkit.Serde(c.data[c.start:end], m, "json")
if e != nil {
return err.Error(packageName, modCursor, "Fetch", e.Error())
}
return nil
}
示例9: InsertOut
func (m *MigrateData) InsertOut(in tk.M, mod orm.IModel) (out int64, e error) {
muinsert := &sync.Mutex{}
valueType := reflect.TypeOf(mod).Elem()
for f := 0; f < valueType.NumField(); f++ {
field := valueType.Field(f)
bsonField := field.Tag.Get("bson")
jsonField := field.Tag.Get("json")
if jsonField != bsonField && field.Name != "RWMutex" && field.Name != "ModelBase" {
in.Set(field.Name, GetMgoValue(in, bsonField))
}
switch field.Type.Name() {
case "string":
if GetMgoValue(in, bsonField) == nil {
in.Set(field.Name, "")
}
break
case "Time":
if GetMgoValue(in, bsonField) == nil {
in.Set(field.Name, time.Time{})
} else {
in.Set(field.Name, GetMgoValue(in, bsonField).(time.Time).UTC())
}
break
default:
break
}
}
e = tk.Serde(in, mod, "json")
if e != nil {
return
}
muinsert.Lock()
out, e = m.BaseController.SqlCtx.InsertOut(mod)
muinsert.Unlock()
return out, e
}
示例10: Find
//func Find(ms []toolkit.M, filters []*Filter) (output []int) {
func Find(ms interface{}, filters []*Filter) (output []int) {
//-- is not a slice
if !toolkit.IsSlice(ms) {
toolkit.Println("Data is not slice")
return []int{}
}
//toolkit.Printf("Find:%s Filter:%s\n", toolkit.JsonString(ms), toolkit.JsonString(filters))
sliceLen := toolkit.SliceLen(ms)
for i := 0; i < sliceLen; i++ {
var v toolkit.M
item := toolkit.SliceItem(ms, i)
e := toolkit.Serde(item, &v, "json")
if e == nil {
match := MatchM(v, filters)
if match {
output = append(output, i)
}
} else {
//toolkit.Println("Serde Fail: ", e.Error(), " Data: ", item)
}
}
return
}
示例11: Fetch
//.........這裏部分代碼省略.........
for _, v2 := range v {
for _, vWhere := range c.whereFields.(toolkit.M) {
if reflect.ValueOf(v2).Kind() == reflect.String {
if strings.ToLower(v2.(string)) == strings.ToLower(vWhere.(string)) {
if len(c.jsonSelect) == 0 {
dataJson = append(dataJson, v)
} else {
foundData = append(foundData, v)
}
}
}
}
}
}
if len(foundData) > 0 {
for _, found := range foundData {
for i, subData := range found {
for _, selected := range c.jsonSelect {
if strings.ToLower(selected) == strings.ToLower(i) {
foundSelected[i] = subData
} else if selected == "*" {
foundSelected[i] = subData
}
}
}
}
dataJson = append(dataJson, foundSelected)
}
}
// toolkit.Unjson(toolkit.Jsonify(dataJson), m)
toolkit.Serde(dataJson, m, "json")
} else {
if c.jsonSelect == nil {
toolkit.Unjson(toolkit.Jsonify(datas), m)
} else {
isSelectedFields := false
for _, selectField := range c.jsonSelect {
if selectField == "*" {
// toolkit.Unjson(toolkit.Jsonify(datas), m)
toolkit.Serde(datas, m, "json")
} else {
isSelectedFields = true
}
}
if isSelectedFields {
for _, v := range datas {
for i, _ := range v {
getRemField[i] = i
}
}
itemToRemove := removeDuplicatesUnordered(getRemField, c.jsonSelect)
for _, found := range datas {
toMap := toolkit.M(found)
for _, remitem := range itemToRemove {
toMap.Unset(remitem)
}
dataJson = append(dataJson, toMap)
}
// toolkit.Unjson(toolkit.Jsonify(dataJson), m)
toolkit.Serde(dataJson, m, "json")
示例12: SaveServers
func (s *ServerController) SaveServers(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
r.Request.ParseMultipartForm(32 << 20)
r.Request.ParseForm()
path := filepath.Join(EC_DATA_PATH, "server", "log")
log, _ := toolkit.NewLog(false, true, path, "log-%s", "20060102-1504")
data := new(colonycore.Server)
if r.Request.FormValue("serviceSSH[type]") == "File" {
log.AddLog("Get forms", "INFO")
dataRaw := map[string]interface{}{}
err := r.GetForms(&dataRaw)
if err != nil {
log.AddLog(err.Error(), "ERROR")
return helper.CreateResult(false, nil, err.Error())
}
log.AddLog("Serding data", "INFO")
err = toolkit.Serde(dataRaw, &data, "json")
if err != nil {
log.AddLog(err.Error(), "ERROR")
return helper.CreateResult(false, nil, err.Error())
}
} else {
log.AddLog("Get payload", "INFO")
err := r.GetPayload(&data)
if err != nil {
log.AddLog(err.Error(), "ERROR")
return helper.CreateResult(false, nil, err.Error())
}
}
if data.ServiceSSH.Type == "File" {
log.AddLog("Fetching public key", "INFO")
reqFileName := "privatekey"
file, _, err := r.Request.FormFile(reqFileName)
if err != nil {
log.AddLog(err.Error(), "ERROR")
return helper.CreateResult(false, nil, err.Error())
}
if file != nil {
log.AddLog("Saving public key", "INFO")
data.ServiceSSH.File = filepath.Join(EC_DATA_PATH, "server", "privatekeys", data.ID)
_, _, err = helper.FetchThenSaveFile(r.Request, reqFileName, data.ServiceSSH.File)
if err != nil {
log.AddLog(err.Error(), "ERROR")
return helper.CreateResult(false, nil, err.Error())
}
}
}
if data.IsAccessValid("node") && data.IsColonyServer {
if data.OS == "linux" {
if err := data.InstallColonyOnLinux(log); err != nil {
return helper.CreateResult(false, nil, err.Error())
}
} else {
if err := data.InstallColonyOnWindows(log); err != nil {
return helper.CreateResult(false, nil, err.Error())
}
}
data.DetectInstalledLang()
data.DetectService()
data.UpdateInternalAppDeploymentStatus("add")
log.AddLog("Restart sedotand", "INFO")
if _, err := data.ToggleSedotanService("start stop", data.ID); err != nil {
log.AddLog(err.Error(), "ERROR")
}
}
if data.IsAccessValid("hdfs") {
log.AddLog(fmt.Sprintf("SSH Connect %v", data), "INFO")
hdfsConfig := hdfs.NewHdfsConfig(data.ServiceHDFS.Host, data.ServiceHDFS.User)
hdfsConfig.Password = data.ServiceHDFS.Pass
hadeepes, err := hdfs.NewWebHdfs(hdfsConfig)
if err != nil {
log.AddLog(err.Error(), "ERROR")
return helper.CreateResult(false, nil, err.Error())
}
_, err = hadeepes.List("/")
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
hadeepes.Config.TimeOut = 5 * time.Millisecond
hadeepes.Config.PoolSize = 100
}
runsrv, e := new(colonycore.ServerService).GetAll()
if e != nil {
return helper.CreateResult(false, nil, e.Error())
}
svr, _, a := data.Connect()
//.........這裏部分代碼省略.........
示例13: Fetch
func (c *Cursor) Fetch(m interface{}, n int, closeWhenDone bool) error {
fmt.Println(c.QueryString)
rows, e := c.session.Query(c.QueryString)
var valueType reflect.Type
if n == 1 {
valueType = reflect.TypeOf(m).Elem()
} else {
valueType = reflect.TypeOf(m).Elem().Elem()
}
if e != nil {
return e
}
defer rows.Close()
columns, e := rows.Columns()
if e != nil {
return e
}
count := len(columns)
tableData := []toolkit.M{}
values := make([]interface{}, count)
valuePtrs := make([]interface{}, count)
// valueint := values
for rows.Next() {
for i := 0; i < count; i++ {
valuePtrs[i] = &values[i]
}
// rows.Scan(valuePtrs...)
rows.Scan(valuePtrs...)
entry := toolkit.M{}
for i, col := range columns {
var v interface{}
val := values[i]
// fmt.Println("Nilai val : ", val)
b, ok := val.([]byte)
if ok {
v = string(b)
} else {
v = val
}
entry.Set(strings.ToLower(col), v)
// entry.Set(col, values[i])
// e = toolkit.DecodeByte(val.([]byte), v)
// toolkit.FromBytes(toolkit.ToBytes(val, ""), "", v)
// entry.Set(col, v)
}
if valueType.Kind() == reflect.Struct {
for i := 0; i < valueType.NumField(); i++ {
namaField := strings.ToLower(valueType.Field(i).Name)
dataType := strings.ToLower(valueType.Field(i).Type.String())
if entry.Has(namaField) {
fmt.Println("isi entry : ", entry[namaField], dataType)
if strings.Contains(dataType, "int") {
entry.Set(namaField,
cast.ToInt(entry[namaField], cast.RoundingAuto))
} else if strings.Contains(dataType, "time.time") {
entry.Set(namaField,
cast.String2Date(cast.ToString(entry[namaField]), "2006-01-02 15:04:05"))
}
}
}
}
tableData = append(tableData, entry)
}
fmt.Println("Nilai table data : ", tableData)
if e != nil {
return e
}
if n == 0 {
// *m.(*[]map[string]interface{}) = tableData
// toolkit.Unjson(toolkit.Jsonify(tableData), m)
e = toolkit.Serde(tableData, m, "json")
fmt.Println("Nilai Model : ", m)
} else {
end := c.start + n
if end > len(tableData) {
e = errors.New("index out of range")
} else {
// *m.(*[]map[string]interface{}) = tableData[0:n]
//toolkit.Unjson(toolkit.Jsonify(tableData[0:n]), m)
e = toolkit.Serde(tableData[0:n], m, "json")
}
}
return e
}
示例14: Fetch
//.........這裏部分代碼省略.........
recData[lowername] = cast.ToF64(val, decimalPoint, cast.RoundingAuto)
case "date":
recData[lowername] = toolkit.String2Date(val, c.headerColumn[i].format) // Just for test
// fmt.Printf("FOR DEBUG : %v \n", c.headerColumn[i].format)
default:
recData[lowername] = val
}
if len(c.ConditionVal.Select) == 0 || c.ConditionVal.Select.Get("*", 0).(int) == 1 {
appendData[orgname] = recData[lowername]
} else {
if c.ConditionVal.Select.Get(strings.ToLower(c.headerColumn[i].name), 0).(int) == 1 {
appendData[orgname] = recData[lowername]
}
}
}
isAppend = c.ConditionVal.getCondition(recData)
if isAppend {
c.count += 1
}
if c.count <= c.ConditionVal.skip || (c.count > (c.ConditionVal.skip+c.ConditionVal.limit) && c.ConditionVal.limit > 0) {
isAppend = false
}
// fmt.Printf("%v - %v \n", v.Elem().Kind(), toolkit.TypeName(v))
if v.Kind() == reflect.Struct || v.Elem().Kind() == reflect.Struct {
tv := v
if v.Elem().Kind() == reflect.Struct {
tv = v.Elem()
}
for i := 0; i < tv.NumField(); i++ {
str := tv.Field(i).Name
fcond := false
if appendData.Has(str) {
fcond = true
} else if appendData.Has(strings.ToLower(str)) {
fcond = true
str = strings.ToLower(str)
} else if strings.ToLower(str) == "id" && appendData.Has("_id") {
str = "_id"
fcond = true
}
if fcond {
switch tv.Field(i).Type.Kind() {
case reflect.Int:
appendData.Set(str, cast.ToInt(appendData[str], cast.RoundingAuto))
case reflect.String:
appendData.Set(str, toolkit.ToString(appendData[str]))
case reflect.Float64:
tstr := toolkit.ToString(appendData[str])
decimalPoint := len(tstr) - (strings.Index(tstr, ".") + 1)
appendData.Set(str, toolkit.ToFloat64(tstr, decimalPoint, toolkit.RoundingAuto))
}
}
}
}
if e == io.EOF {
if isAppend && len(appendData) > 0 {
toolkit.Serde(appendData, iv, "json")
ivs = reflect.Append(ivs, reflect.ValueOf(iv).Elem())
lineCount += 1
}
break
} else if e != nil {
return errorlib.Error(packageName, modCursor,
"Fetch", e.Error())
}
if isAppend && len(appendData) > 0 {
toolkit.Serde(appendData, iv, "json")
ivs = reflect.Append(ivs, reflect.ValueOf(iv).Elem())
lineCount += 1
}
if n > 0 {
if lineCount >= n {
break
}
}
}
if e != nil {
return errorlib.Error(packageName, modCursor, "Fetch", e.Error())
}
if n == 1 && reflect.ValueOf(m).Elem().Kind() != reflect.Slice {
if ivs.Len() > 0 {
reflect.ValueOf(m).Elem().Set(ivs.Index(0))
}
} else {
reflect.ValueOf(m).Elem().Set(ivs)
}
return nil
}
示例15: Parse
func Parse(header []string, in interface{}, m interface{}, outputType string, dateFormat string) (e error) {
if !toolkit.IsPointer(m) {
return errorlib.Error("", "", "Fetch", "Model object should be pointer")
}
slice := false
var ins []string
if reflect.ValueOf(m).Elem().Kind() == reflect.Slice || toolkit.TypeName(in) == "[]string" {
slice = true
ins = in.([]string)
} else {
ins = append(ins, in.(string))
}
if outputType == CSV {
var v reflect.Type
if slice && toolkit.TypeName(m) != "*interface {}" {
v = reflect.TypeOf(m).Elem().Elem()
} else {
v = reflect.TypeOf(m).Elem()
}
ivs := reflect.MakeSlice(reflect.SliceOf(v), 0, 0)
for _, data := range ins {
appendData := toolkit.M{}
iv := reflect.New(v).Interface()
reader := csv.NewReader(strings.NewReader(""))
if strings.Contains(data, "','") {
reader = csv.NewReader(strings.NewReader("\"" + strings.Trim(strings.Replace(data, "','", "\",\"", -1), "'") + "\""))
} else {
reader = csv.NewReader(strings.NewReader(data))
}
record, e := reader.Read()
if e != nil {
return e
}
if v.Kind() == reflect.Struct {
for i := 0; i < v.NumField(); i++ {
appendData[v.Field(i).Name] = strings.TrimSpace(record[i])
valthis := appendData[v.Field(i).Name]
switch v.Field(i).Type.Kind() {
case reflect.Int:
appendData.Set(v.Field(i).Name, cast.ToInt(valthis, cast.RoundingAuto))
case reflect.Int16:
appendData.Set(v.Field(i).Name, cast.ToInt(valthis, cast.RoundingAuto))
case reflect.Int32:
appendData.Set(v.Field(i).Name, cast.ToInt(valthis, cast.RoundingAuto))
case reflect.Int64:
appendData.Set(v.Field(i).Name, cast.ToInt(valthis, cast.RoundingAuto))
case reflect.Float32:
valf, _ := strconv.ParseFloat(valthis.(string), 32)
appendData.Set(v.Field(i).Name, valf)
case reflect.Float64:
valf, _ := strconv.ParseFloat(valthis.(string), 64)
appendData.Set(v.Field(i).Name, valf)
case reflect.Bool:
valf, _ := strconv.ParseBool(valthis.(string))
appendData.Set(v.Field(i).Name, valf)
default:
dtype := DetectDataType(valthis.(string), dateFormat)
if dtype == "date" {
valf := cast.String2Date(valthis.(string), dateFormat)
appendData.Set(v.Field(i).Name, valf)
}
}
}
} else {
if len(header) == 0 {
e = errorlib.Error("", "", "Parse Out", "Header cant be null because object is not struct")
return e
}
for i, val := range header {
appendData[val] = strings.TrimSpace(record[i])
valthis := appendData[val]
dtype := DetectDataType(valthis.(string), dateFormat)
if dtype == "int" {
appendData.Set(val, cast.ToInt(valthis, cast.RoundingAuto))
} else if dtype == "float" {
valf, _ := strconv.ParseFloat(valthis.(string), 64)
appendData.Set(val, valf)
} else if dtype == "date" {
valf := cast.String2Date(valthis.(string), dateFormat)
appendData.Set(val, valf)
} else if dtype == "bool" {
valf, _ := strconv.ParseBool(valthis.(string))
appendData.Set(val, valf)
}
}
}
toolkit.Serde(appendData, iv, JSON)
ivs = reflect.Append(ivs, reflect.ValueOf(iv).Elem())
}
if slice {
reflect.ValueOf(m).Elem().Set(ivs)
//.........這裏部分代碼省略.........