misc updates
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Paul 2021-11-13 12:58:33 +01:00
parent 70145c1504
commit 5828b0c016
9 changed files with 65 additions and 28 deletions

View File

@ -16,7 +16,7 @@ build() {
echo "Drone tag set, let's do a release" echo "Drone tag set, let's do a release"
VERSION=${DRONE_TAG} VERSION=${DRONE_TAG}
echo "${PROJECTNAME} ${VERSION}" > /build/VERSION echo "${PROJECTNAME} ${VERSION}" > /build/VERSION
elif [[ ! -z ${DRONE_TAG} ]] else
then then
echo "Drone not set, let's only do a build" echo "Drone not set, let's only do a build"
VERSION=${DRONE_COMMIT} VERSION=${DRONE_COMMIT}

2
go.mod
View File

@ -50,6 +50,4 @@ require (
github.com/syndtr/goleveldb v1.0.0 // indirect github.com/syndtr/goleveldb v1.0.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.1 // indirect github.com/valyala/fasttemplate v1.2.1 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/tools v0.1.2 // indirect
) )

View File

@ -18,9 +18,9 @@ func (config *Config) GetConfig() error {
flag.Usage = utils.Usage flag.Usage = utils.Usage
flag.StringVar(&configfile, "configfile", "qrz.ini", "config file to use with qrz section") flag.StringVar(&configfile, "configfile", "qrz.ini", "config file to use with qrz section")
flag.IntVar(&port, "port", 8080, "web port to use") flag.IntVar(&port, "port", 8080, "http port to use")
flag.BoolVar(&nofeed, "nofeed", false, "no feed database table with entries at first launch") flag.BoolVar(&nofeed, "nofeed", false, "do not feed table with entries at first launch")
flag.BoolVar(&debug, "debug", false, "if debug logging must be enabled") flag.BoolVar(&debug, "debug", false, "enable debug")
flag.Parse() flag.Parse()
cfg, err := ini.Load(configfile) cfg, err := ini.Load(configfile)
@ -33,6 +33,7 @@ func (config *Config) GetConfig() error {
config.Port = port config.Port = port
config.NoFeed = nofeed config.NoFeed = nofeed
config.Debug = debug config.Debug = debug
config.DbType = qrzsection.Key("db_type").MustString("postgres")
config.DbHostname = qrzsection.Key("db_hostname").MustString("localhost") config.DbHostname = qrzsection.Key("db_hostname").MustString("localhost")
config.DbName = qrzsection.Key("db_name").MustString("database") config.DbName = qrzsection.Key("db_name").MustString("database")
config.DbUsername = qrzsection.Key("db_username").MustString("username") config.DbUsername = qrzsection.Key("db_username").MustString("username")
@ -50,6 +51,7 @@ func (config *Config) GetConfig() error {
// Config is the global config of qrz // Config is the global config of qrz
type Config struct { type Config struct {
Db *xorm.Engine Db *xorm.Engine
DbType string
DbHostname string DbHostname string
DbName string DbName string
DbUsername string DbUsername string

View File

@ -13,12 +13,24 @@ import (
// Initialize creates connection to database and exec Schema // Initialize creates connection to database and exec Schema
func Initialize(config *config.Config) (err error) { func Initialize(config *config.Config) (err error) {
config.Db, err = xorm.NewEngine("postgres", var connstr string
fmt.Sprintf("postgres://%s:%s@%s/%s", switch config.DbType {
case "mysql":
connstr = fmt.Sprintf("%s:%s@%s/%s",
config.DbUsername, config.DbUsername,
config.DbPassword, config.DbPassword,
config.DbHostname, config.DbHostname,
config.DbName)) config.DbName)
default:
// postgresql by default
connstr = fmt.Sprintf("%s://%s:%s@%s/%s",
config.DbType,
config.DbUsername,
config.DbPassword,
config.DbHostname,
config.DbName)
}
config.Db, err = xorm.NewEngine(config.DbType, connstr)
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }

View File

@ -33,7 +33,10 @@ func Run(config config.Config) (err error) {
for _, group := range groups { for _, group := range groups {
url := fmt.Sprintf(config.URLBase, group) url := fmt.Sprintf(config.URLBase, group)
log.Println(fmt.Sprintf("Processing the %s group with URL %s", group, url)) 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 {
@ -75,8 +78,14 @@ func getGroups(urlbase string) (groups []string, err error) {
clt := &http.Client{} clt := &http.Client{}
resp, err := clt.Get(urlbase) resp, err := clt.Get(urlbase)
a, err := ioutil.ReadAll(resp.Body) if err != nil {
retstr := string(a) log.Println(err)
}
pagebody, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Println(err)
}
retstr := string(pagebody)
b := re1.FindStringSubmatch(retstr) b := re1.FindStringSubmatch(retstr)
body := b[1] body := b[1]
@ -195,6 +204,9 @@ func insertFrsEntryToDB(config config.Config, frsPeople map[string]Qrz) (err err
for _, frs := range frsPeople { for _, frs := range frsPeople {
_, err = session.Insert(&frs) _, err = session.Insert(&frs)
if err != nil {
log.Println(err)
}
qrzNum++ qrzNum++
if (qrzNum % 5) == 0 { if (qrzNum % 5) == 0 {
err = session.Commit() err = session.Commit()
@ -239,12 +251,12 @@ func ToSlice(qrz Qrz) (out []string) {
// Qrz describe FRS people // Qrz describe FRS people
type Qrz struct { type Qrz struct {
ID int `db:"id" xorm:"pk autoincr"` ID int `db:"id" xorm:"pk autoincr"`
DMRID string `db:"dmrid" xorm:"varchar(50) notnull"` QRZ string `db:"qrz" xorm:"index notnull"`
QRZ string `db:"qrz" xorm:"varchar(50) notnull"` DMRID string `db:"dmrid" xorm:"notnull"`
Name string `db:"name" xorm:"varchar(50) notnull"` Name string `db:"name" xorm:"index notnull"`
Address string `db:"address" xorm:"varchar(50) notnull"` Address string `db:"address" xorm:"notnull"`
City string `db:"city" xorm:"varchar(50) notnull"` City string `db:"city" xorm:"index notnull"`
Zipcode string `db:"zipcode" xorm:"varchar(5) notnull"` Zipcode string `db:"zipcode" xorm:"index varchar(5) notnull"`
Dept string `db:"dept" xorm:"varchar(50) notnull"` Dept string `db:"dept" xorm:"index notnull"`
Country string `db:"country" xorm:"varchar(50) notnull"` Country string `db:"country" xorm:"index notnull"`
} }

View File

@ -4,6 +4,7 @@ package qrzws
import ( import (
"fmt" "fmt"
"log"
"net/http" "net/http"
"regexp" "regexp"
"strings" "strings"
@ -25,7 +26,10 @@ func RunServer(config config.Config) (err error) {
templatesbox := packr.New("templates", "../../templates") templatesbox := packr.New("templates", "../../templates")
staticbox := packr.New("static", "../../static") staticbox := packr.New("static", "../../static")
builtTemplates, _ := templates.BuildTemplates(templatesbox) builtTemplates, err := templates.BuildTemplates(templatesbox)
if err != nil {
log.Println(err)
}
e := echo.New() e := echo.New()
e.HideBanner = true e.HideBanner = true

View File

@ -3,6 +3,7 @@
package static package static
import ( import (
"log"
"net/http" "net/http"
"strings" "strings"
@ -13,7 +14,10 @@ import (
// GetStatic returns static file content // GetStatic returns static file content
func GetStatic(box *packr.Box, c echo.Context) (err error) { func GetStatic(box *packr.Box, c echo.Context) (err error) {
name := c.Param("*") name := c.Param("*")
cnt, _ := box.FindString(name) cnt, err := box.FindString(name)
if err != nil {
log.Println(err)
}
if strings.HasSuffix(name, ".js") { if strings.HasSuffix(name, ".js") {
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJavaScript) c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJavaScript)
} else if strings.HasSuffix(name, ".css") { } else if strings.HasSuffix(name, ".css") {

View File

@ -28,7 +28,10 @@ func BuildTemplates(box *packr.Box) (builttemplates *Template, err error) {
tmpl := template.New("templates") tmpl := template.New("templates")
for _, filename := range box.List() { for _, filename := range box.List() {
tmplContent, _ := box.FindString(filename) tmplContent, err := box.FindString(filename)
if err != nil {
log.Println(err)
}
tmpl.New(filename).Parse(tmplContent) tmpl.New(filename).Parse(tmplContent)
} }
@ -47,12 +50,18 @@ func BuildTemplatesDir(dir string) (builttemplates *Template, err error) {
if err != nil { if err != nil {
return err return err
} }
freader, _ := pkger.Open(path) freader, err := pkger.Open(path)
if err != nil {
log.Println(err)
}
tmplContent, err := ioutil.ReadAll(freader) tmplContent, err := ioutil.ReadAll(freader)
tmpl.New(info.Name()).Parse(string(tmplContent)) tmpl.New(info.Name()).Parse(string(tmplContent))
log.Println(info.Name(), tmplContent) log.Println(info.Name(), tmplContent)
return err return err
}) })
if err != nil {
log.Println(err)
}
builttemplate := &Template{ builttemplate := &Template{
templates: tmpl, templates: tmpl,

4
vendor/modules.txt vendored
View File

@ -146,8 +146,6 @@ golang.org/x/net/http2
golang.org/x/net/http2/h2c golang.org/x/net/http2/h2c
golang.org/x/net/http2/hpack golang.org/x/net/http2/hpack
golang.org/x/net/idna golang.org/x/net/idna
# golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
## explicit
# golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf # golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf
## explicit; go 1.17 ## explicit; go 1.17
golang.org/x/sys/internal/unsafeheader golang.org/x/sys/internal/unsafeheader
@ -179,8 +177,6 @@ golang.org/x/text/secure/bidirule
golang.org/x/text/transform golang.org/x/text/transform
golang.org/x/text/unicode/bidi golang.org/x/text/unicode/bidi
golang.org/x/text/unicode/norm golang.org/x/text/unicode/norm
# golang.org/x/tools v0.1.2
## explicit; go 1.17
# gopkg.in/ini.v1 v1.62.0 # gopkg.in/ini.v1 v1.62.0
## explicit ## explicit
gopkg.in/ini.v1 gopkg.in/ini.v1