err := conn.WriteControl(websocket.PingMessage, []byte("Hello"), time.Now().Add(time.Second)) if err != nil { log.Println("Error writing Ping message:", err) }
err := conn.WriteControl(websocket.CloseMessage, []byte("Goodbye"), time.Now().Add(time.Second)) if err != nil { log.Println("Error writing Close message:", err) }In this example, we are sending a close message to the WebSocket connection with the message "Goodbye". We also set a timeout of one second. If there is an error writing the message, it will be logged. This can be used to close the WebSocket connection. The package library used in these examples is github.com/gorilla/websocket.