50 lines
1013 B
Go
50 lines
1013 B
Go
package main
|
|
|
|
import (
|
|
"database/sql"
|
|
"encoding/json"
|
|
"fmt"
|
|
_ "github.com/go-sql-driver/mysql"
|
|
"log"
|
|
"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)
|
|
}
|
|
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
|
|
}
|
|
// 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)
|
|
}
|
|
}
|