package main import ( "log" "net/http" "github.com/gorilla/websocket" ) var upgrader = websocket.Upgrader{} func echoHandler(w http.ResponseWriter, r *http.Request) { conn, err := upgrader.Upgrade(w, r, nil) if err != nil { log.Println(err) return } defer conn.Close() for { messageType, message, err := conn.ReadMessage() if err != nil { log.Println(err) return } log.Printf("Received message: %s\n", message) err = conn.WriteMessage(messageType, message) if err != nil { log.Println(err) return } } } func main() { http.HandleFunc("/", echoHandler) log.Fatal(http.ListenAndServe(":8080", nil)) }This example creates an HTTP server that listens on the default port (8080) and upgrades incoming requests to WebSocket connections using the Upgrader. Inside the echoHandler function, the WebSocket connection is passed to a loop that reads incoming messages and logs them to the console. The same message is then sent back to the client using the conn.WriteMessage method. Overall, the github.com/gorilla.websocket package provides a powerful API for building real-time applications with WebSockets. The Upgrader is a critical piece of this API, as it provides a straightforward way to upgrade HTTP connections to WebSocket connections.