4.2 mux 使用bug

1. 运行环境

win10/go 1.19

2. 问题描述?

  • mux这段代码可能已经过时

    homeURL, _ := router.Get("home").URL()
    fmt.Println("homeURL: ", homeURL)
  • router.Get返回的是*Router,其结构为

    type Route struct {
      // Request handler for the route.
      handler http.Handler
      // If true, this route never matches: it is only used to build URLs.
      buildOnly bool
      // The name used to build URLs.
      name string
      // Error resulted from building a route.
      err error
    
      // "global" reference to all named routes
      namedRoutes map[string]*Route
    
      // config possibly passed in from `Router`
      routeConf
    }

    这里要获取的是name,可以通过GetName方法拿到Router的name,所以应该为

    homeURL := router.Get("home")
    fmt.Println("homeURL:", homeURL.GetName())
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!