43 lines
935 B
Go
43 lines
935 B
Go
package importer
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
)
|
|
|
|
func (i *Importer) importFromJSON(file string) {
|
|
i.log.Info().Msgf("importing from JSON file: %s", file)
|
|
data, err := ioutil.ReadFile(file)
|
|
if err != nil {
|
|
i.log.Error().Err(err).Msg("failed to read JSON file")
|
|
return
|
|
}
|
|
|
|
var records []map[string]interface{}
|
|
if err := json.Unmarshal(data, &records); err != nil {
|
|
i.log.Error().Err(err).Msg("failed to unmarshal JSON")
|
|
return
|
|
}
|
|
|
|
//totalRecords := len(records)
|
|
|
|
/*
|
|
bar := progressbar.NewOptions(totalRecords,
|
|
progressbar.OptionSetDescription("Importing records"),
|
|
progressbar.OptionShowCount(),
|
|
progressbar.OptionShowIts(),
|
|
progressbar.OptionSetPredictTime(true),
|
|
)
|
|
*/
|
|
|
|
/*
|
|
for _, record := range records {
|
|
// Insert record into the database
|
|
// db.InsertRecord(record) // Replace with actual database insertion logic
|
|
bar.Add(1)
|
|
}
|
|
*/
|
|
|
|
i.log.Info().Msg("JSON import completed")
|
|
}
|