#Task This command is a little different than the other ones because it uses a WebSocket instead of the standard HTTP protocol: ```go var consoleCmd = &cobra.Command{ Use: "console", Short: "View logs on a server by ID", Long: ``, Run: func(cmd *cobra.Command, args []string) { serverIDFlag, err := cmd.Flags().GetInt("server-id") insecureFlag, err := cmd.Flags().GetBool("insecure") if err != nil { fmt.Println("Please specify server-id with '-i'") return } url := fmt.Sprintf("wss://"+os.Getenv("API_URL")+"ws/logs/%d", serverIDFlag) fmt.Println("Dialing: ", url) authToken := config.GetToken() headers := http.Header{} headers.Add("Authorization", "Bearer "+authToken) dialer := websocket.DefaultDialer if insecureFlag { dialer.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} } conn, _, err := dialer.Dial(url, headers) if err != nil { fmt.Println("Error occured dialing websocket: ", err) // body, err := io.ReadAll(resp.Body) // if err != nil { // fmt.Println("Failed to read response body", err) // return // } // fmt.Println("Handshake failed with status:", resp.Status) // fmt.Println("Response body:", string(body)) return } defer conn.Close() for { _, msg, err := conn.ReadMessage() if err != nil { fmt.Println("Error occurred reading message: ", err) } fmt.Println(string(msg)) } }, } ``` - We get our flags, create our websocket URL by appending the `serverIDFlag` to the end of the URL path, get our auth token then we get more specific: - since we're using `net/http`, we have to add our headers differently than with resty - if we have the `--insecure` flag set, we can skip the SSL verification - we dial the URL and defer the connection close for after our infinite for loop breaks - then until the loop breaks, we read each message from the connection. This is what enables us to see real time logs for each Minecraft server! See [Develop CLI Helpers Module](../../Python%20API/Tasks/Core%20API%20Functionality/Develop%20CLI%20Helpers%20Module.md) for the API implementation.