如何从Go自定义类型中获取底层变量

huangapple go评论91阅读模式
英文:

How to get underlying variable from Go custom type

问题

我正在尝试通过只导入自己的库到主代码中,并使用一个辅助函数来使用gorequest下载页面,来抽象化使用gorequest。.End()方法返回一个gorequest.Response,一个字符串(包含页面内容)和一个错误切片(如果存在)。

gorequest.Response只是一个声明为type Response *http.Responsehttp.Response

为了防止将该库导入其他go文件中,我该如何从gorequest.Response类型中获取底层的http.Response

英文:

I'm trying to abstract the use of gorequest by only importing my own libraries into the main code and using a helper to download a page using gorequest. The .End() method returns a gorequest.Response, a string (containing the body) and a slice of errors if present.

The gorequest.Response it's just an http.Response declared as type Response *http.Response

In order to prevent importing the library into other go files, how could I get the underlying http.Response from the gorequest.Response type?

答案1

得分: 1

根据你提供的内容,我可以为你进行翻译:

我认为gorequest.Response只是指向http.Response的指针,所以你可以这样做:

var response http.Response
response = *gorequest.Response

这样应该可以帮助你将其作为指针传递。

英文:

It looks to me that gorequest.Response is just a pointer to http.Response so you could do something like:

var response http.Response
response = *gorequest.Response

And that should help you pass it as a pointer.

huangapple
  • 本文由 发表于 2014年6月25日 14:15:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/24401474.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定