First of all, we need to know that in go the method name capitalized is the method to be exported (that is, public method), while lowercase is not the method of export (private).
Go does not provide automatic support for get and set methods. For the recommended practice of setting the Get Set method, see Code:
Package Main Import"FMT"type Foostruct{Namestring} //Set Methodfunc (f*foo) SetName (namestring) {F.name=name}//get method, without using GET, just capitalize the first letter. func (f Foo) Name ()string {returnF.name} func main () {p:=Foo{}p.setname ("ABC") Name:=p.name () fmt. PRINTLN (name)}
Summary: The Get method does not need to add a get string, the direct property name uppercase as the method name, the set method requires a property before the set string as the method name.
How to write get and set methods in the Go language