A
A
asdasda112017-11-04 23:52:43
go
asdasda11, 2017-11-04 23:52:43

What is the structure of a function in Go?

I had to parse a piece of go-code here, although I don’t write on it. Can you tell me what this syntax means?

func (book *Book) findData(user user.User) bool {
...
err = database.Conn.QueryRow(....).Scan(&book.Object.id, &book.Object.Text)
...
if ...
return true
}

What is book *Book? Judging by the code, I understand that user is a function parameter, i.e. sent when called. bool is what the function will return. But what is book?
Or will it return both bool and also &book.Object.id, &book.Object.Text ? Scan some more...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
index0h, 2017-11-05
@asdasda11

book is a struct whose method is this function

M
mrobespierre, 2017-11-10
@mrobespierre

book is a receiver, a data type that has this method. above they wrote that the receiver has the type "structure", so it is in this case, and so it is in 99% of other cases, but we must not forget an important nuance - in Go, any data type can have methods (not only struct) , either string or int

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question