code cleaning and performances improvements
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
ef3b816729
commit
cca6c96626
@ -19,8 +19,10 @@ var version string
|
|||||||
func main() {
|
func main() {
|
||||||
var cfg config.Config
|
var cfg config.Config
|
||||||
cfg.GetConfig()
|
cfg.GetConfig()
|
||||||
|
|
||||||
cfg.Version = version
|
cfg.Version = version
|
||||||
|
|
||||||
|
// Generate static files embedding
|
||||||
PackrGen()
|
PackrGen()
|
||||||
|
|
||||||
err := database.Initialize(&cfg)
|
err := database.Initialize(&cfg)
|
||||||
@ -31,15 +33,16 @@ func main() {
|
|||||||
|
|
||||||
err = qrz.InitCronConfig(cfg)
|
err = qrz.InitCronConfig(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = qrzws.RunServer(cfg)
|
err = qrzws.RunServer(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PackrGen act as an assets bundle maker
|
||||||
func PackrGen() {
|
func PackrGen() {
|
||||||
packr.New("static", "../../static")
|
packr.New("static", "../../static")
|
||||||
packr.New("templates", "../../templates")
|
packr.New("templates", "../../templates")
|
||||||
|
@ -24,37 +24,41 @@ func InitCronConfig(config config.Config) (err error) {
|
|||||||
|
|
||||||
// Run runs the main loop
|
// Run runs the main loop
|
||||||
func Run(config config.Config) (err error) {
|
func Run(config config.Config) (err error) {
|
||||||
|
existingQrz, err := getCurrentEntries(config)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
|
||||||
for _, group := range config.QrzGroups {
|
for _, group := range config.QrzGroups {
|
||||||
url := fmt.Sprintf(config.URLBase, group)
|
url := fmt.Sprintf(config.URLBase, group)
|
||||||
fmt.Println(fmt.Sprintf("Processing the %s group", group))
|
log.Println(fmt.Sprintf("Processing the %s group with URL %s", group, url))
|
||||||
|
|
||||||
bodyStr, err := getBody(url)
|
bodyStr, err := getBody(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Println(err)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
frsPeople, err := getFrsEntries(config, bodyStr)
|
frsPeople, err := getFrsEntries(config, bodyStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Println(err)
|
||||||
}
|
break
|
||||||
|
|
||||||
existingQrz, err := getCurrentEntries(config)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalln(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = discardExistingEntries(config, &frsPeople, existingQrz)
|
err = discardExistingEntries(config, &frsPeople, existingQrz)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Println(err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(frsPeople) > 0 {
|
if len(frsPeople) > 0 {
|
||||||
err = insertFrsEntryToDB(config, frsPeople)
|
err = insertFrsEntryToDB(config, frsPeople)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Println(
|
log.Println(
|
||||||
fmt.Sprintf("No entry to insert in database for group %s",
|
fmt.Sprintf("No entry to insert in database for group %s",
|
||||||
group))
|
group))
|
||||||
}
|
}
|
||||||
@ -153,7 +157,7 @@ func insertFrsEntryToDB(config config.Config, frsPeople map[string]Qrz) (err err
|
|||||||
|
|
||||||
var qrzNum int
|
var qrzNum int
|
||||||
|
|
||||||
fmt.Println(
|
log.Println(
|
||||||
fmt.Sprintf("Starting insert of %d entries",
|
fmt.Sprintf("Starting insert of %d entries",
|
||||||
len(frsPeople)))
|
len(frsPeople)))
|
||||||
|
|
||||||
@ -172,7 +176,7 @@ func insertFrsEntryToDB(config config.Config, frsPeople map[string]Qrz) (err err
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println(fmt.Sprintf("Committed %d qrz entries", qrzNum))
|
log.Println(fmt.Sprintf("Committed %d qrz entries", qrzNum))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -69,23 +69,24 @@ func Run(c echo.Context, config config.Config) (res QrzDatatableOutput, err erro
|
|||||||
|
|
||||||
rows, err := BuildQuery(config, qrzinputjson)
|
rows, err := BuildQuery(config, qrzinputjson)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, b := range rows {
|
if len(rows) > 0 {
|
||||||
res.Data = append(res.Data, qrz.ToSlice(b))
|
for _, b := range rows {
|
||||||
|
res.Data = append(res.Data, qrz.ToSlice(b))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
res.Data = append(res.Data, []string{"", "", "", "", "", ""})
|
||||||
}
|
}
|
||||||
|
|
||||||
res.RecordsFiltered, err = BuildQCntFil(config, qrzinputjson)
|
res.RecordsFiltered, err = BuildQCntFil(config, qrzinputjson)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err, "filtered")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
res.RecordsTotal, err = BuildQCntTot(config, qrzinputjson)
|
res.RecordsTotal, err = BuildQCntTot(config, qrzinputjson)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err, "total")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
package templates
|
package templates
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ func BuildTemplatesDir(dir string) (builttemplates *Template, err error) {
|
|||||||
freader, _ := pkger.Open(path)
|
freader, _ := pkger.Open(path)
|
||||||
tmplContent, err := ioutil.ReadAll(freader)
|
tmplContent, err := ioutil.ReadAll(freader)
|
||||||
tmpl.New(info.Name()).Parse(string(tmplContent))
|
tmpl.New(info.Name()).Parse(string(tmplContent))
|
||||||
fmt.Println(info.Name(), tmplContent)
|
log.Println(info.Name(), tmplContent)
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user