The main
function copies the mux
value when calling the TableHandler
function. The TableHandler
function modifies the copy. This value is discarded on return from the TableHandler
function. The result is the handler is not registered in main()
's mux.
The fix is to change the TableHandler
argument type from http.ServeMux
to *http.ServeMux
.
import ( "net/http" )
func main() {
mux := http.NewServeMux()
handlers.TableHandler(mux) // <--- pass pointer here
}
func TableHandler(mux *http.ServeMux) { // <--- declare arg as pointer
mux.HandleFunc("/gpdp/v1/prices/", func(w http.ResponseWriter, r *http.Request)
log.Println("request for prices: ", r.Method, r.Body)
...}
The application stopped working because of a change to http.ServeMux in 2016. This change exposed the problem in the application. Copying http.ServeMux
values was never supported. The go vet
command prints a warning when http.ServeMux
values are copied.