嘿,我是 Go 语法的新手。我将如何使用此功能?抛出我的部分是函数声明开头的指针?
func (p *Pointer) FunctionName(arg string) error {
dec := json.NewDecoder(strings.NewReader(arg))
err := dec.Decode(&p)
return err
}
最佳答案
在 Go 中,结构类型可以包含方法,这就是你在这里所拥有的。假设我有以下代码:
type Foo struct {
Something string
}
func (f * Foo) PrintSomething() {
fmt.Println(f.Something)
}
我不能直接调用 PrintSomething
,我必须使用 Foo
类型的变量来调用它。示例:
f := Foo{
Something: "Something",
}
f.PrintSomething()
关于go - 我如何在 Golang 中使用这个函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52995925/