import ( "github.com/gorilla/websocket" "net/http" ) func handler(w http.ResponseWriter, r *http.Request) { upgrader := websocket.Upgrader{} conn, err := upgrader.Upgrade(w, r, nil) if err != nil { // handle error } remoteAddr := conn.RemoteAddr() // use remoteAddr for logging or debugging }
import ( "github.com/gorilla/websocket" "net/http" ) func handler(w http.ResponseWriter, r *http.Request) { upgrader := websocket.Upgrader{} conn, err := upgrader.Upgrade(w, r, nil) if err != nil { // handle error } // read from and write to `conn` as needed }In this example, the `Upgrader.Upgrade()` method is used to upgrade the HTTP connection to a WebSocket connection. The resulting `conn` variable can be used to read from and write to the WebSocket connection.