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

如何从Go中的reflect.Value获取指针?

As far as I know methods with pointer receivers only implement interfaces for pointers. I want to utilize the encoding.TextMarshaler interface which must be implmented with a pointer. How can I therefore obtain a pointer using reflection.

The following does not work because as mentionend a value does not implement the interface:

v.Interface().(encoding.TextUnmarshaler)

Use v.Addr().Interface().(encoding.TextUnmarshaler) to get the address. This assumes that v references an addressable value.

近期文章

  • 导入Vault / builtin / credential / aws会将测试标记添加到命令行应用程序
  • 从go中获取mongo的普通json
  • 在Go中初始化成员时是否只能使用返回值之一?
  • 请说明golang类型是否按值传递
  • 什么时候应该在通道上使用互斥锁?
  • 来自NodeJS的Golang解密AES 256 CBC base64
  • 太多的结果导致欧拉计画#145的循环
  • Golang客户端在Aerospike中的CDT列表上执行操作
  • 如何将HTTP内容流式传输到文件和缓冲区?
  • 不能在返回参数中使用msgs(类型<-chan _)作为类型chan _
  • 带通道的WaitGroup goroutines
  • 将map转换为json在golang中给出了很多整数
  • 功能可以在Go中实现接口
  • 如何在Golang中测试恐慌?
  • 具有动态模式的Golang和Yaml
  • 使用带有cypher / aes的if-construction不一致的Go错误返回
  • Golang多模板缓存
  • 在文档中创建用户定义的键
  • 在Golang中分割字串
  • 将C数组和指针代码转换为Go

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

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

友情链接:代码精华