Migrated URL validation out of database saving

This commit is contained in:
2018-11-17 17:07:33 +00:00
committed by cdramey
parent 5c669c8b93
commit 9f13f8e09b
3 changed files with 23 additions and 18 deletions

17
load.go
View File

@ -42,29 +42,34 @@ func loadjson(stor storage.Storage, filename string) error {
max = e.ID
}
qurl := &qurl.QURL{
q := &qurl.QURL{
ID: e.ID,
URL: e.URL,
}
if e.Date.Date > 0 {
qurl.Created = time.Unix((e.Date.Date / 1000), 0)
q.Created = time.Unix((e.Date.Date / 1000), 0)
}
if e.IP != "" {
qurl.IP = net.ParseIP(e.IP)
q.IP = net.ParseIP(e.IP)
}
if e.Browser != "" {
qurl.Browser = e.Browser
q.Browser = e.Browser
}
err := stor.AddQURL(qurl)
err := q.CheckValid()
if err != nil {
fmt.Printf("\nError adding qurl: %s\n", err.Error())
fmt.Printf("\nValidation failure: %s\n", err.Error())
continue
}
err = stor.AddQURL(q)
if err != nil {
return fmt.Errorf("AddQURL() Database error: %s", err.Error())
}
count++
if (count % 100) == 0 {
fmt.Printf("*")