package main import ( "context" "encoding/json" "flag" "fmt" "os" "time" "github.com/mcstatus-io/mcutil/v4/status" ) func main() { // Define flags hostname := flag.String("host", "my-mc.link", "Minecraft server hostname") port := flag.Int("port", 25565, "Minecraft server port") flag.Parse() // Create context with timeout ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel() // Query server status response, err := status.Modern(ctx, *hostname, uint16(*port)) if err != nil { fmt.Fprintf(os.Stderr, "Error: %v\n", err) os.Exit(1) } // Convert response to formatted JSON jsonOutput, err := json.MarshalIndent(response, "", " ") if err != nil { fmt.Fprintf(os.Stderr, "Error marshaling JSON: %v\n", err) os.Exit(1) } // Print JSON fmt.Println(string(jsonOutput)) }