updated qrz sources
This commit is contained in:
parent
55759f8e65
commit
4cf0aaeb58
@ -12,6 +12,7 @@ import (
|
||||
func (config *Config) GetConfig() error {
|
||||
var configfile string
|
||||
var nofeed bool
|
||||
var debug bool
|
||||
var port int
|
||||
|
||||
flag.Usage = utils.Usage
|
||||
@ -19,6 +20,7 @@ func (config *Config) GetConfig() error {
|
||||
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.Parse()
|
||||
|
||||
cfg, err := ini.Load(configfile)
|
||||
@ -30,6 +32,7 @@ func (config *Config) GetConfig() error {
|
||||
|
||||
config.Port = port
|
||||
config.NoFeed = nofeed
|
||||
config.Debug = debug
|
||||
config.DbHostname = qrzsection.Key("db_hostname").MustString("localhost")
|
||||
config.DbName = qrzsection.Key("db_name").MustString("database")
|
||||
config.DbUsername = qrzsection.Key("db_username").MustString("username")
|
||||
@ -55,5 +58,6 @@ type Config struct {
|
||||
Cron string
|
||||
Port int
|
||||
NoFeed bool
|
||||
Debug bool
|
||||
Version string
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ func Initialize(config *config.Config) (err error) {
|
||||
|
||||
config.Db.SetMapper(names.GonicMapper{})
|
||||
config.Db.CreateTables(qrz.Qrz{})
|
||||
config.Db.ShowSQL(true)
|
||||
config.Db.ShowSQL(config.Debug)
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -167,15 +167,32 @@ func insertFrsEntryToDB(config config.Config, frsPeople map[string]Qrz) (err err
|
||||
return nil
|
||||
}
|
||||
|
||||
// ToSlice converts struct to array
|
||||
/* func ToSlice(qrz Qrz) (out []interface{}) {
|
||||
val := reflect.ValueOf(qrz)
|
||||
num := val.NumField()
|
||||
|
||||
for i := 1; i < num-1; i++ {
|
||||
out = append(out, val.Field(i).Interface())
|
||||
}
|
||||
return
|
||||
} */
|
||||
|
||||
// ToSlice converts struct to array
|
||||
func ToSlice(qrz Qrz) (out []string) {
|
||||
out = []string{qrz.QRZ, qrz.Name, qrz.City, qrz.Dept, qrz.Country, qrz.DMRID}
|
||||
return
|
||||
}
|
||||
|
||||
// Qrz describe FRS people
|
||||
type Qrz struct {
|
||||
ID int `db:"id" xorm:"pk autoincr"`
|
||||
QRZ string `db:"qrz" xorm:"varchar(25) notnull"`
|
||||
DMRID string `db:"dmrid" xorm:"varchar(25) notnull"`
|
||||
Name string `db:"name" xorm:"varchar(25) 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(25) notnull"`
|
||||
Country string `db:"country" xorm:"varchar(25) notnull"`
|
||||
DMRID string `db:"dmrid" xorm:"varchar(25) notnull"`
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package qrzws
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
@ -40,19 +41,12 @@ func RunServer(config config.Config) (err error) {
|
||||
}
|
||||
return c.JSON(http.StatusOK, res)
|
||||
})
|
||||
/*e.GET("/export_frs.csv", func(c echo.Context) (err error) {
|
||||
e.GET("/export_frs.csv", func(c echo.Context) (err error) {
|
||||
data, mime, err := RunCSVExport(c, config)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
return c.Blob(http.StatusOK, mime, data)
|
||||
})*/
|
||||
e.GET("/test", func(c echo.Context) (err error) {
|
||||
res, err := Test(c, config)
|
||||
if err != nil {
|
||||
return c.String(http.StatusInternalServerError, fmt.Sprintf("Erreur 500 ta mère: %d", res))
|
||||
}
|
||||
return c.JSON(http.StatusOK, res)
|
||||
})
|
||||
|
||||
if !config.NoFeed {
|
||||
@ -62,14 +56,6 @@ func RunServer(config config.Config) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// Test runs the main loop
|
||||
func Test(c echo.Context, config config.Config) (cnt int64, err error) {
|
||||
//config.Db.Where("qrz LIKE '%%' OR name LIKE '%%' OR city LIKE '%%' OR dept LIKE '%%' OR country LIKE '%%' OR dmrid LIKE '%%'").Limit(50, 2).Desc("id").Select("*").Find(&qrz)
|
||||
cnt, err = config.Db.SQL("select count(*) from qrz").Count()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Run runs the main loop
|
||||
func Run(c echo.Context, config config.Config) (res QrzDatatableOutput, err error) {
|
||||
qrzinputjson := new(QrzDatatableInput)
|
||||
@ -85,7 +71,7 @@ func Run(c echo.Context, config config.Config) (res QrzDatatableOutput, err erro
|
||||
}
|
||||
|
||||
for _, b := range rows {
|
||||
res.Data = append(res.Data, b)
|
||||
res.Data = append(res.Data, qrz.ToSlice(b))
|
||||
}
|
||||
|
||||
res.RecordsFiltered, err = BuildQueryCountFiltered(config, *qrzinputjson)
|
||||
@ -141,14 +127,14 @@ func BuildQuery(config config.Config, qrzdt QrzDatatableInput) (qrz []qrz.Qrz, e
|
||||
// BuildQueryCountFiltered builds query for counting filtered
|
||||
func BuildQueryCountFiltered(config config.Config, qrzdt QrzDatatableInput) (cnt int64, err error) {
|
||||
searchstatement, err := SetSearchLike(config, qrzdt)
|
||||
cnt, err = config.Db.SQL(fmt.Sprintf("select count(*) from qrz WHERE %s", searchstatement)).Count()
|
||||
cnt, err = config.Db.SQL(fmt.Sprintf("SELECT COUNT(*) FROM qrz WHERE %s", searchstatement)).Count()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// BuildQueryCountTotal builds query for counting totals
|
||||
func BuildQueryCountTotal(config config.Config, qrzdt QrzDatatableInput) (cnt int64, err error) {
|
||||
cnt, err = config.Db.SQL("select count(*) from qrz").Count()
|
||||
cnt, err = config.Db.SQL("SELECT COUNT(*) FROM qrz").Count()
|
||||
|
||||
return
|
||||
}
|
||||
@ -233,33 +219,20 @@ func SetSearchLike(config config.Config, qrzdt QrzDatatableInput) (searchstmt st
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
// RunCSVExport runs the main loop
|
||||
func RunCSVExport(c echo.Context, config config.Config) (data []byte, mime string, err error) {
|
||||
mime = "text/csv"
|
||||
res, err := config.Db.Exec(config.DbStatements.ExportCSV)
|
||||
var q []qrz.Qrz
|
||||
var res []string
|
||||
res = append(res, "QRZ,Name,City,Dept,Country")
|
||||
for rows.Next() {
|
||||
var l []string
|
||||
results := make(map[string]interface{})
|
||||
err = rows.MapScan(results)
|
||||
colslice, _ := rows.Columns()
|
||||
for _, column := range colslice {
|
||||
if results[column] == nil {
|
||||
l = append(l, "")
|
||||
} else {
|
||||
l = append(l, fmt.Sprintf("%s", results[column]))
|
||||
}
|
||||
}
|
||||
line := strings.Join(l, ",")
|
||||
res = append(res, line)
|
||||
err = config.Db.Asc("qrz").Find(&q)
|
||||
res = append(res, "QRZ,Name,City,Dept,Country,DMRID")
|
||||
for _, item := range q {
|
||||
res = append(res, strings.Join(qrz.ToSlice(item), ","))
|
||||
}
|
||||
data = []byte(strings.Join(res, "\n"))
|
||||
|
||||
return
|
||||
}
|
||||
*/
|
||||
|
||||
// QrzDatatableInput describes datatable query
|
||||
type QrzDatatableInput struct {
|
||||
@ -288,8 +261,8 @@ type QrzDatatableInput struct {
|
||||
|
||||
// QrzDatatableOutput describes datatable response
|
||||
type QrzDatatableOutput struct {
|
||||
Data []qrz.Qrz `json:"data"`
|
||||
Draw int `json:"draw"`
|
||||
RecordsTotal int64 `json:"recordsTotal"`
|
||||
RecordsFiltered int64 `json:"recordsFiltered"`
|
||||
Data [][]string `json:"data"`
|
||||
Draw int `json:"draw"`
|
||||
RecordsTotal int64 `json:"recordsTotal"`
|
||||
RecordsFiltered int64 `json:"recordsFiltered"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user