英文:
How to get underlying variable from Go custom type
问题
我正在尝试通过只导入自己的库到主代码中,并使用一个辅助函数来使用gorequest下载页面,来抽象化使用gorequest。.End()
方法返回一个gorequest.Response,一个字符串(包含页面内容)和一个错误切片(如果存在)。
gorequest.Response
只是一个声明为type Response *http.Response
的http.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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论