1

I got an error message: cannot use websocket.Handler(handler) (type websocket.Handler) as type func(http.ResponseWriter, *http.Request) in argument to mx.HandleFunc

in following code

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)
}

1 Answer 1

3

I believe you should use mx.Handle, not mx.HandleFunc

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.