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 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制