我从1.6golang升级到1.9 (和1.10),所有其他调用现在都返回404。他们的成绩很好,只有1.6分。
main.go
import ( "net/http" )
func main() {
mux := http.NewServeMux()
handlers.TableHandler(*mux)
}table_handler.go
func TableHandler(mux http.ServeMux) {
mux.HandleFunc("/gpdp/v1/prices/", func(w http.ResponseWriter, r *http.Request)
log.Println("request for prices: ", r.Method, r.Body)
...}发布于 2018-05-18 00:59:02
main函数在调用TableHandler函数时复制TableHandler值。TableHandler函数修改副本。此值在从TableHandler函数返回时被丢弃。结果是处理程序没有在main()的mux中注册。
修复方法是将TableHandler参数类型从http.ServeMux更改为*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)
...}由于2016年改为http.ServeMux,应用程序停止工作。此更改暴露了应用程序中的问题。从来不支持复制http.ServeMux值。go vet命令在复制http.ServeMux值时打印警告。
https://stackoverflow.com/questions/50400760
复制相似问题