dou426098 2017-04-26 13:30
浏览 698
已采纳

如何在Golang路由中将URL作为参数传递?

I'm trying to pass a URL as a parameter in Golang, and I haven't been able to find a solution in all of the tutorials I've looked at. The problem is that I can only get the url to return minus a crucial forward slash.

My handler looks like this:

router.HandleFunc("/new/{url}", createURL)

So the request would look like:

www.myapp.heroku.com/new/https://www.google.com

However, the url that I results is missing a slash:

http:/www.google.com

I sure it's probably got something to do with RFC3986, but is there a way to pass in the url as it is?

  • 写回答

2条回答 默认 最新

  • drllqg2903 2018-03-14 02:01
    关注

    This particular behavior in Gorilla Mux can be changed by setting SkipClean to true.

    router := mux.NewRouter()
    router.SkipClean(true)
    router.HandleFunc("/new/", index)
    router.HandleFunc("/", index)
    http.ListenAndServe(":"+port, router)
    

    The relevant documentation can be found here.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上