conn, _ := websocket.Dial("ws://example.com/websocket", "", "http://example.com") conn.SetReadDeadline(time.Now().Add(30 * time.Second))
func handleConnection(ws *websocket.Conn) { // Set a read deadline of 60 seconds ws.SetReadDeadline(time.Now().Add(60 * time.Second)) // Read a message from the connection _, message, err := ws.ReadMessage() if err != nil { log.Println("Error reading message:", err) return } // Do something with the message } func main() { http.Handle("/", websocket.Handler(handleConnection)) http.ListenAndServe(":8080", nil) }In this example, we're setting a read deadline of 60 seconds for a WebSocket connection in a WebSocket handler function. We then read a message from the connection and do something with it. This example is part of a larger program that sets up a WebSocket server using the gorilla.websocket package.