我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

如何在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:

fmt.Fprint(w,r.URL)

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

What should I do?

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

Try this.

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

http://golang.org/pkg/net/url/#URL.String

近期文章

  • 在方法内部默认情况下会取消对指针的引用吗?
  • 这样在Go中会更有效吗?
  • 在Gorilla Mux中嵌套子路由器
  • GoLang中的小“ a:”是什么意思?
  • Golang模板中的变量
  • 延长左侧的切片长度
  • 如何在Go中GZIP压缩http请求?
  • 在特定结构中解组Json数据
  • 如何在gRPC中使用预定义的protobuf类型(即“ google / protobuf / timestamp.proto”)
  • 队列上有多重队列
  • 具有联合声明/赋值运算符的全局变量内联赋值和另一个未声明的变量丢失范围?
  • 由fmt.Sprint(e)在Error方法内部产生的无限循环
  • 切片的零值不为nil
  • 使用Go编写iPhone应用程序的库
  • request.Post数组提交后为空
  • Golang无法从request.GetBody()获取正文
  • 日期的字符串日期[重复]
  • Helm _helpers.tpl:在其他模板定义中调用定义的模板
  • Golang:获取切片的类型
  • 我该如何分批处理流程?

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华