Answer the question
In order to leave comments, you need to log in
I can not understand the meaning of the function in go?
Hi there is an example function
func (p *Page) save() error {
filename := p.Title + ".txt"
return ioutil.WriteFile(filename, p.Body, 0600)
}
func (p *page)
Answer the question
In order to leave comments, you need to log in
This is a function of an object that is of type Page . In simple terms, you cannot call save() globally , but you must call the p.save() function on the object . Accordingly, access to the object will be organized inside the function.
type Page struct{}
func (p*Page) save() error{
log.Println(p) // тут доступ к экземпляру у которого вызывается метод
return nil
}
p:=&Page{}
err:=p.save()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question