msg := []byte("Hello, World!") err := conn.Write(msg) if err != nil { log.Println("Error writing message:", err) }
type Message struct { Text string Time time.Time } msg := Message{Text: "Hello, World!", Time: time.Now()} err := websocket.JSON.Send(conn, &msg) if err != nil { log.Println("Error writing message:", err) }In this example, we are defining a custom `Message` struct, populating it with some data, and then sending it to the WebSocket connection using `websocket.JSON.Send` function. This function takes care of marshalling the struct to JSON and sending it as the message content. Both examples use the `golang.org.x.net.websocket` package library to work with WebSocket connections in Go.