2012-12-15 21:56
浏览 210

如何在GO,Google App Engine中将* url.URL转换为字符串

I would like to get the URL and convert it to string. I have to following code:

func getURL(w http.ResponseWriter, r *http.Request) {
    var url string = r.URL

I get this:

"cannot convert r.URL (type *url.URL) to type string"

This is working well:


But I would like to use it, not just print it.

What should I do?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douxing9813 2012-12-15 21:59

    The url.URL type has a .String() method.

    Try this.

    func getURL(w http.ResponseWriter, r *http.Request) {
        url := r.URL.String()

    点赞 1 打赏 评论