August 2019
Beginner to intermediate
798 pages
17h 2m
English
A Go type method is a function with a special receiver argument. You declare methods as ordinary functions with an additional parameter that appears in front of the function name. This particular parameter connects the function to the type of that extra parameter. As a result, that parameter is called the receiver of the method.
The following Go code is the implementation of the Close() function as found in https://golang.org/src/os/file_plan9.go:
func (f *File) Close() error {
if err := f.checkValid("close"); err != nil {
return err
}
return f.file.close()
}
The Close() function is a type method because there is that (f *File) parameter in front of its name and after the func keyword. The f parameter is called the receiver ...
Read now
Unlock full access