I find a lot of examples of how to make a websocket service in Go that accepts ws connections, but not one to send them. Since the ws request is initially executed as a normal rest request, I try something like this
request, err := http.NewRequest("GET", "ws://localhost:8081/ws", nil)
if err != nil {
fmt.Println(err)
return
}
_, err = http.DefaultClient.Do(request)
if err != nil {
fmt.Println(err)
return
}
client := newClient(*websocket.Conn) // how i can get *websocket.Conn?
go client.Read()
go client.Write()
clientsMap.Add(client)
But this obviously doesn't work, I get an unsupported protocol scheme "ws" error. How do I make a ws connection and get *websocket.Conn?