dtcuv8044 2018-10-25 18:31
浏览 23
已采纳

如何在Golang中使用此功能?

Hey I'm new to Go syntax. How would I use this function? The part that is throwing me is the pointer at the beginning of the function declaration?

func (p *Pointer) FunctionName(arg string) error {
  dec := json.NewDecoder(strings.NewReader(arg))
  err := dec.Decode(&p)
  return err
}
  • 写回答

3条回答 默认 最新

  • drl959975 2018-10-25 18:34
    关注

    FunctionName is a method on *Pointer.

    If you are asking how to use the code on arbitrary types and not just a *Pointer, then write it as a function:

    func FunctionName(v interface{}, arg string) error {
      dec := json.NewDecoder(strings.NewReader(arg))
      err := dec.Decode(v)
      return err
    }
    

    Assuming that p is a variable of type *Pointer, then call it like this:

    FunctionName(p, "{... JSON text here }")
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥20 sim800c模块 at指令及平台
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计