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