func Upload_menus(ctx *gin.Context) error {
type System_menus struct {
Menuid string `json:"menuid"`
Parent_order string `json:"parent_order"`
Parent_name string `json:"parent_name"`
Parent_icon string `json:"parent_icon"`
Parent_url string `json:"parent_url"`
Parent_badge string `json:"parent_badge"`
Childlevel1_order string `json:"childlevel1_order"`
Childlevel1_name string `json:"childlevel1_name"`
Childlevel1_url string `json:"childlevel1_url"`
Childlevel1_icon string `json:"childlevel1_icon"`
Childlevel1_badge string `json:"childlevel1_badge"`
Childlevel2_order string `json:"childlevel2_order"`
Childlevel2_name string `json:"childlevel2_name"`
Childlevel2_url string `json:"childlevel2_url"`
Childlevel2_icon string `json:"childlevel2_icon"`
Childlevel2_badge string `json:"childlevel2_badge"`
}
var (
err error
systemmenus []System_menus
)
_filename, err := ctx.FormFile("file")
if err != nil {
return err
}
sExcelfile := _filename.Filename
sExcelfile = filepath.Join(easyglobal.APPPATH, "EXCEL", sExcelfile)
easyglobal.Excel, err = excelize.OpenFile(sExcelfile)
if err != nil {
return err
}
// Get all the excel_rows in the Sheet1.
excel_rows, err := easyglobal.Excel.GetRows("MENUS")
if err != nil {
return err
}
for nIndex, Rows := range excel_rows {
if nIndex < 6 {
continue
}
if len(Rows) <= 0 {
continue
}
if len(Rows[0]) <= 0 {
continue
}
var (
systemmenu System_menus
)
x := []byte(Rows)
err = json.Unmarshal(x, &systemmenu)
if err != nil {
return errors.New("Error here : " + err.Error())
}
systemmenus = append(systemmenus, systemmenu)
}
if len(systemmenus) > 0 {
tx, err := easyglobal.Db.Beginx()
if err != nil {
return err
}
defer func(tx *sqlx.Tx) {
if err != nil {
_ = tx.Rollback()
} else {
_ = tx.Commit()
}
}(tx)
_, err = tx.NamedExec(appquery.IU_systemmenu, systemmenus)
if err != nil {
return err
}
}
return nil
}
I am getting error “x := byte(Rows)” I can not transfer string to byte .
I am trying to transfer row data to struct .