go-nurl/import/importer.go
Martin Donnelly e1d7d78aed Init
2024-09-16 17:06:11 +01:00

48 lines
802 B
Go

package _import
import (
"encoding/json"
"io"
"log"
"os"
"time"
)
type Data struct {
Visits int64 `json:"visits"`
LongUrl string `json:"long_url"`
CreatedAt time.Time `json:"created_at,omitempty"`
Id int64 `json:"_id"`
}
func DoImport() []Data {
jsonFile, err := os.Open("./data.json")
// if we os.Open returns an error then handle it
if err != nil {
log.Fatalln(err)
}
log.Println("Successfully Opened data.json")
// defer the closing of our jsonFile so that we can parse it later on
defer jsonFile.Close()
byteValue, _ := io.ReadAll(jsonFile)
data := []Data{}
json.Unmarshal(byteValue, &data)
/* for _, v := range data {
log.Println("v", v)
errr := postImport(app, v)
if errr != nil {
log.Fatalln(errr)
}
}
*/
return data
}