mysql
This commit is contained in:
@ -18,6 +18,15 @@ type Config struct {
|
|||||||
TelnetServer bool `yaml:"telnetserver"`
|
TelnetServer bool `yaml:"telnetserver"`
|
||||||
FlexRadioSpot bool `yaml:"flexradiospot"`
|
FlexRadioSpot bool `yaml:"flexradiospot"`
|
||||||
} `yaml:"general"`
|
} `yaml:"general"`
|
||||||
|
Database struct {
|
||||||
|
MySQL bool `yaml:"mysql"`
|
||||||
|
SQLite bool `yaml:"sqlite"`
|
||||||
|
MySQLUser string `yaml:"mysql_db_user"`
|
||||||
|
MySQLPassword string `yaml:"mysql_db_password"`
|
||||||
|
MySQLDbName string `yaml:"mysql_db_name"`
|
||||||
|
MySQLHost string `yaml:"mysql_host"`
|
||||||
|
MySQLPort string `yaml:"mysql_port"`
|
||||||
|
} `yaml:"database"`
|
||||||
SQLite struct {
|
SQLite struct {
|
||||||
SQLitePath string `yaml:"sqlite_path"`
|
SQLitePath string `yaml:"sqlite_path"`
|
||||||
Callsign string `yaml:"callsign"`
|
Callsign string `yaml:"callsign"`
|
||||||
|
10
config.yml
10
config.yml
@ -1,9 +1,17 @@
|
|||||||
general:
|
general:
|
||||||
delete_log_file_at_start: true
|
delete_log_file_at_start: true
|
||||||
log_to_file: true
|
log_to_file: true
|
||||||
log_level: INFO # INFO or DEBUG or WARN
|
log_level: DEBUG # INFO or DEBUG or WARN
|
||||||
telnetserver: true # not in use for now
|
telnetserver: true # not in use for now
|
||||||
flexradiospot: true # not in use for now
|
flexradiospot: true # not in use for now
|
||||||
|
database:
|
||||||
|
mysql: true #only one of the two can be true
|
||||||
|
sqlite: false
|
||||||
|
mysql_db_user: rouggy
|
||||||
|
mysql_db_password: 89DGgg290379
|
||||||
|
mysql_db_name: log_f4bpo
|
||||||
|
mysql_host: 10.10.10.15
|
||||||
|
mysql_port: 3306
|
||||||
sqlite:
|
sqlite:
|
||||||
sqlite_path: 'C:\Perso\Seafile\Radio\Logs\Log4OM\F4BPO.SQLite' # SQLite Db oath of Log4OM
|
sqlite_path: 'C:\Perso\Seafile\Radio\Logs\Log4OM\F4BPO.SQLite' # SQLite Db oath of Log4OM
|
||||||
callsign: F4BPO # Log4OM Callsign used to check if you get spotted by someone
|
callsign: F4BPO # Log4OM Callsign used to check if you get spotted by someone
|
||||||
|
27
database.go
27
database.go
@ -9,6 +9,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -37,6 +39,18 @@ type FlexDXClusterRepository struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewLog4OMContactsRepository(filePath string) *Log4OMContactsRepository {
|
func NewLog4OMContactsRepository(filePath string) *Log4OMContactsRepository {
|
||||||
|
|
||||||
|
if Cfg.Database.MySQL {
|
||||||
|
db, err := sql.Open("mysql", Cfg.Database.MySQLUser+":"+Cfg.Database.MySQLPassword+"@tcp("+Cfg.Database.MySQLHost+":"+Cfg.Database.MySQLPort+")/"+Cfg.Database.MySQLDbName)
|
||||||
|
if err != nil {
|
||||||
|
Log.Errorf("Cannot open db", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Log4OMContactsRepository{
|
||||||
|
db: db,
|
||||||
|
Log: Log}
|
||||||
|
|
||||||
|
} else if Cfg.Database.SQLite {
|
||||||
db, err := sql.Open("sqlite3", filePath)
|
db, err := sql.Open("sqlite3", filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Log.Errorf("Cannot open db", err)
|
Log.Errorf("Cannot open db", err)
|
||||||
@ -51,6 +65,9 @@ func NewLog4OMContactsRepository(filePath string) *Log4OMContactsRepository {
|
|||||||
Log: Log}
|
Log: Log}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func NewFlexDXDatabase(filePath string) *FlexDXClusterRepository {
|
func NewFlexDXDatabase(filePath string) *FlexDXClusterRepository {
|
||||||
|
|
||||||
db, err := sql.Open("sqlite3", filePath)
|
db, err := sql.Open("sqlite3", filePath)
|
||||||
@ -95,6 +112,16 @@ func NewFlexDXDatabase(filePath string) *FlexDXClusterRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Log4OMContactsRepository) CountEntries() int {
|
||||||
|
var contacts int
|
||||||
|
_ = r.db.QueryRow("SELECT COUNT(*) FROM log").Scan(&contacts)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("could not query database", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return contacts
|
||||||
|
}
|
||||||
|
|
||||||
func (r *Log4OMContactsRepository) ListByCountry(countryID string, contactsChan chan []Contact, wg *sync.WaitGroup) {
|
func (r *Log4OMContactsRepository) ListByCountry(countryID string, contactsChan chan []Contact, wg *sync.WaitGroup) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
rows, err := r.db.Query("SELECT callsign, band, mode, dxcc, stationcallsign, country FROM log WHERE dxcc = ?", countryID)
|
rows, err := r.db.Query("SELECT callsign, band, mode, dxcc, stationcallsign, country FROM log WHERE dxcc = ?", countryID)
|
||||||
|
2
go.mod
2
go.mod
@ -3,6 +3,7 @@ module git.rouggy.com/rouggy/FlexDXCluster
|
|||||||
go 1.23.1
|
go 1.23.1
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/go-sql-driver/mysql v1.9.3
|
||||||
github.com/mattn/go-sqlite3 v1.14.23
|
github.com/mattn/go-sqlite3 v1.14.23
|
||||||
github.com/sirupsen/logrus v1.9.3
|
github.com/sirupsen/logrus v1.9.3
|
||||||
github.com/x-cray/logrus-prefixed-formatter v0.5.2
|
github.com/x-cray/logrus-prefixed-formatter v0.5.2
|
||||||
@ -10,6 +11,7 @@ require (
|
|||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
filippo.io/edwards25519 v1.1.0 // indirect
|
||||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.16 // indirect
|
github.com/mattn/go-isatty v0.0.16 // indirect
|
||||||
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
|
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
|
||||||
|
4
go.sum
4
go.sum
@ -1,9 +1,13 @@
|
|||||||
|
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||||
|
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||||
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||||
|
github.com/go-sql-driver/mysql v1.9.3 h1:U/N249h2WzJ3Ukj8SowVFjdtZKfu9vlLZxjPXV1aweo=
|
||||||
|
github.com/go-sql-driver/mysql v1.9.3/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU=
|
||||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
|
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
|
||||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||||
|
4
main.go
4
main.go
@ -42,7 +42,7 @@ func main() {
|
|||||||
cfg := NewConfig(cfgPath)
|
cfg := NewConfig(cfgPath)
|
||||||
|
|
||||||
log := NewLog()
|
log := NewLog()
|
||||||
log.Info("Running FlexDXCluster version 0.5")
|
log.Info("Running FlexDXCluster version 0.6")
|
||||||
log.Infof("Callsign: %s", cfg.SQLite.Callsign)
|
log.Infof("Callsign: %s", cfg.SQLite.Callsign)
|
||||||
|
|
||||||
DeleteDatabase("./flex.sqlite", log)
|
DeleteDatabase("./flex.sqlite", log)
|
||||||
@ -61,6 +61,8 @@ func main() {
|
|||||||
|
|
||||||
// Database connection to Log4OM
|
// Database connection to Log4OM
|
||||||
cRepo := NewLog4OMContactsRepository(cfg.SQLite.SQLitePath)
|
cRepo := NewLog4OMContactsRepository(cfg.SQLite.SQLitePath)
|
||||||
|
contacts := cRepo.CountEntries()
|
||||||
|
log.Infof("Log4OM Database Contains %v Contacts", contacts)
|
||||||
defer cRepo.db.Close()
|
defer cRepo.db.Close()
|
||||||
|
|
||||||
TCPServer := NewTCPServer(cfg.TelnetServer.Host, cfg.TelnetServer.Port)
|
TCPServer := NewTCPServer(cfg.TelnetServer.Host, cfg.TelnetServer.Port)
|
||||||
|
5
spot.go
5
spot.go
@ -27,7 +27,10 @@ type TelnetSpot struct {
|
|||||||
CallsignWorked bool
|
CallsignWorked bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// var spotNumber = 1
|
||||||
|
|
||||||
func ProcessTelnetSpot(re *regexp.Regexp, spotRaw string, SpotChanToFlex chan TelnetSpot, SpotChanToHTTPServer chan TelnetSpot, Countries Countries) {
|
func ProcessTelnetSpot(re *regexp.Regexp, spotRaw string, SpotChanToFlex chan TelnetSpot, SpotChanToHTTPServer chan TelnetSpot, Countries Countries) {
|
||||||
|
|
||||||
match := re.FindStringSubmatch(spotRaw)
|
match := re.FindStringSubmatch(spotRaw)
|
||||||
|
|
||||||
if len(match) != 0 {
|
if len(match) != 0 {
|
||||||
@ -144,6 +147,8 @@ func ProcessTelnetSpot(re *regexp.Regexp, spotRaw string, SpotChanToFlex chan Te
|
|||||||
// Log.Infof("Could not decode: %s", strings.Trim(spotRaw, "\n"))
|
// Log.Infof("Could not decode: %s", strings.Trim(spotRaw, "\n"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log.Infof("Spots Processed: %v", spotNumber)
|
||||||
|
// spotNumber++
|
||||||
}
|
}
|
||||||
|
|
||||||
func (spot *TelnetSpot) GetBand() {
|
func (spot *TelnetSpot) GetBand() {
|
||||||
|
Reference in New Issue
Block a user