我收到一条错误消息:不能在 mx.HandleFunc 的参数中使用 websocket.Handler(handler)(类型 websocket.Handler)作为类型 func(http.ResponseWriter, *http.Request)
在下面的代码中
package main
import (
"golang.org/x/net/websocket"
"net/http"
)
func handler(ws *websocket.Conn) {
// TODO
}
func main() {
mx := http.NewServeMux()
mx.HandleFunc("/ws", websocket.Handler(handler)) // error
http.ListenAndServe("localhost:8888", mx)
}
最佳答案
我相信你应该使用mx.Handle
,而不是mx.HandleFunc
关于go - 如何在 Go 中将 websocket 与 NewServeMux 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46520738/