msgType, data, err := conn.ReadMessage() if err != nil { log.Println("error reading message:", err) return } switch msgType { case websocket.TextMessage: log.Println("received text message:", string(data)) case websocket.BinaryMessage: log.Println("received binary message of length", len(data)) case websocket.CloseMessage: closeErr := websocket.FormatCloseMessage(websocket.CloseNormalClosure, "") err = conn.WriteControl(websocket.CloseMessage, closeErr, time.Now().Add(writeTimeout)) if err != nil { log.Println("error closing connection:", err) } }Here, we use `Conn.ReadMessage` to read the incoming message and determine its message type. If it's a text or binary message, we print the data. If it's a close message, we send a close message back and close the connection. Note that this code uses the Gorilla websocket library, which is available at `github.com/gorilla/websocket`.