web server displays queried servers now
This commit is contained in:
parent
9a646cca88
commit
7243500197
5 changed files with 37 additions and 9 deletions
24
cmd/main.go
24
cmd/main.go
|
@ -8,6 +8,7 @@ import (
|
|||
"io/ioutil"
|
||||
"encoding/json"
|
||||
|
||||
"git.snrd.de/Spaenny/steamServer"
|
||||
"git.snrd.de/Spaenny/steamServer/postgres"
|
||||
"git.snrd.de/Spaenny/steamServer/web"
|
||||
"github.com/robfig/cron/v3"
|
||||
|
@ -29,17 +30,25 @@ func main() {
|
|||
log.Fatal(err)
|
||||
}
|
||||
|
||||
serverString := "s.spenny.tf"
|
||||
|
||||
c := cron.New()
|
||||
c.AddFunc("*/1 * * * *", func() { updateServers(serverString) })
|
||||
c.Start()
|
||||
ss, err := store.Servers()
|
||||
if err != nil {
|
||||
log.Fatal("There is no server in the list.")
|
||||
}
|
||||
|
||||
for _, s := range ss {
|
||||
serverString := s.ServerIP
|
||||
c := cron.New()
|
||||
c.AddFunc("*/1 * * * *", func() { updateServers(serverString, store) })
|
||||
c.Start()
|
||||
}
|
||||
|
||||
|
||||
h := web.NewHandler(store)
|
||||
http.ListenAndServe(":3000", h)
|
||||
}
|
||||
|
||||
func updateServers(serverString string) {
|
||||
func updateServers(serverString string, store steamServer.Store) {
|
||||
url := "http://api.spenny.eu/server/" + serverString
|
||||
|
||||
reqClient := http.Client {
|
||||
|
@ -66,8 +75,9 @@ func updateServers(serverString string) {
|
|||
}
|
||||
|
||||
|
||||
server := Server{}
|
||||
server := steamServer.Server{}
|
||||
json.Unmarshal([]byte(body), &server)
|
||||
fmt.Println(server)
|
||||
store.UpdateServerByQuery(&server)
|
||||
fmt.Println(&server)
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue