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"
VERSION=${DRONE_TAG}
echo "${PROJECTNAME} ${VERSION}" > /build/VERSION
elif [[ ! -z ${DRONE_TAG} ]]
else
then
echo "Drone not set, let's only do a build"
VERSION=${DRONE_COMMIT}

2
go.mod
View File

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

View File

@ -13,12 +13,24 @@ import (
// Initialize creates connection to database and exec Schema
func Initialize(config *config.Config) (err error) {
config.Db, err = xorm.NewEngine("postgres",
fmt.Sprintf("postgres://%s:%s@%s/%s",
var connstr string
switch config.DbType {
case "mysql":
connstr = fmt.Sprintf("%s:%s@%s/%s",
config.DbUsername,
config.DbPassword,
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 {
log.Fatalln(err)
}

View File

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

View File

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

View File

@ -3,6 +3,7 @@
package static
import (
"log"
"net/http"
"strings"
@ -13,7 +14,10 @@ import (
// GetStatic returns static file content
func GetStatic(box *packr.Box, c echo.Context) (err error) {
name := c.Param("*")
cnt, _ := box.FindString(name)
cnt, err := box.FindString(name)
if err != nil {
log.Println(err)
}
if strings.HasSuffix(name, ".js") {
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJavaScript)
} 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")
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)
}
@ -47,12 +50,18 @@ func BuildTemplatesDir(dir string) (builttemplates *Template, err error) {
if err != nil {
return err
}
freader, _ := pkger.Open(path)
freader, err := pkger.Open(path)
if err != nil {
log.Println(err)
}
tmplContent, err := ioutil.ReadAll(freader)
tmpl.New(info.Name()).Parse(string(tmplContent))
log.Println(info.Name(), tmplContent)
return err
})
if err != nil {
log.Println(err)
}
builttemplate := &Template{
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/hpack
golang.org/x/net/idna
# golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
## explicit
# golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf
## explicit; go 1.17
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/unicode/bidi
golang.org/x/text/unicode/norm
# golang.org/x/tools v0.1.2
## explicit; go 1.17
# gopkg.in/ini.v1 v1.62.0
## explicit
gopkg.in/ini.v1