2024-08-22 19:33:17 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-08-23 12:19:44 +02:00
|
|
|
"database/sql"
|
2024-08-22 19:33:17 +02:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2024-08-23 12:19:44 +02:00
|
|
|
_ "github.com/go-sql-driver/mysql"
|
|
|
|
"log"
|
2024-08-22 19:33:17 +02:00
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
//resp, err := PingHostname("play.survival-games.cz", 25565)
|
|
|
|
resp, err := PingHostname("127.0.0.2", 25565)
|
|
|
|
//resp, err := PingHostname("vps.brn.systems", 25965)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Ty debil")
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2024-08-23 12:19:44 +02:00
|
|
|
connectionBytes, err := os.ReadFile("secrets/.myconnectionstring")
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
db, err := sql.Open("mysql", string(connectionBytes))
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
defer func(db *sql.DB) {
|
|
|
|
err := db.Close()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}(db)
|
|
|
|
err = saveResponse(db, resp)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
return
|
|
|
|
}
|
2024-08-22 19:33:17 +02:00
|
|
|
// Pretty print the response
|
|
|
|
respJson, err := json.MarshalIndent(resp, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Error marshalling response to JSON:", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err = os.WriteFile("out/server.json", respJson, 0644)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Error creating server.json:", err)
|
|
|
|
}
|
|
|
|
}
|