make use of template engine, add footer
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Philipp 2021-10-01 22:49:47 +02:00
parent 4fd2f099b8
commit 48d9621adf
6 changed files with 278 additions and 259 deletions

View file

@ -1,6 +1,7 @@
package main
import (
"time"
"log"
"net/http"
@ -24,20 +25,49 @@ func main() {
log.Fatal("There is an issue with the databse: %w", err)
}
var addedServers []string
for _, server := range addedServers {
println(server)
}
for _, s := range ss {
serverString := s.ServerIP
c := cron.New()
c.AddFunc("*/1 * * * *", func() { updateServers(serverString, store) })
c.Start()
if !stringInSlice(s.ServerIP, addedServers) {
addedServers = append(addedServers, s.ServerIP)
c := cron.New()
c.AddFunc("*/1 * * * *", func() { updateServers(serverString, store) })
c.Start()
}
}
cronjob := cron.New()
cronjob.AddFunc("*/5 * * * *", func() {
for _, s := range ss {
serverString := s.ServerIP
if !stringInSlice(s.ServerIP, addedServers) {
addedServers = append(addedServers, s.ServerIP)
c := cron.New()
c.AddFunc("*/1 * * * *", func() { updateServers(serverString, store) })
c.Start()
}
}
})
cronjob.Start()
h := web.NewHandler(store)
http.ListenAndServe(":3000", h)
}
func stringInSlice(a string, list []string) bool {
for _, b := range list {
if b == a {
return true
}
}
return false
}
func updateServers(host string, store steamServer.Store) {
client, err := a2s.NewClient(host)
client, err := a2s.NewClient(host, a2s.TimeoutOption(time.Second * 10))
if err != nil {
log.Fatal("Creation of client failed: %w", err)
@ -50,6 +80,13 @@ func updateServers(host string, store steamServer.Store) {
if err != nil {
log.Printf("Querying failed: %s", err)
server := steamServer.Server {
Name: host,
Map: "Server didn't reply.",
Players: 0,
}
store.UpdateServerByQuery(&server, host)
return
}