import ( "github.com/gorilla/websocket" "time" ) func main() { // create new WebSocket connection conn, _, err := websocket.DefaultDialer.Dial("ws://localhost:8080", nil) if err != nil { panic(err) } // set write deadline to 5 seconds deadline := time.Now().Add(5 * time.Second) conn.SetWriteDeadline(deadline) // write message to WebSocket err = conn.WriteMessage(websocket.TextMessage, []byte("Hello, world!")) if err != nil { panic(err) } }
import ( "github.com/gorilla/websocket" "time" ) func main() { // create new WebSocket connection conn, _, err := websocket.DefaultDialer.Dial("ws://localhost:8080", nil) if err != nil { panic(err) } // set infinite write deadline conn.SetWriteDeadline(time.Time{}) // write message to WebSocket err = conn.WriteMessage(websocket.TextMessage, []byte("Hello, world!")) if err != nil { panic(err) } }In example 1, we set a write deadline of 5 seconds before writing a message to the WebSocket. In example 2, we set an infinite write deadline, allowing the write operation to take as long as it needs.