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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了