This is a creation in Article, where the information may have evolved or changed.
Today there is a confusing place where a lot of novices may encounter (especially in Java before)
The properties of the object-oriented part of the Golang (the bottom line is that process is a method of the mysession struct, and the Golang uses a snippet of code to add a code fragment to a struct or class that is subordinate to his execution method, The attributes you have are defined in-house, as in Java. )
Type MySession struct{
In string
Out string
}
Func (Session mysession) process (Xmlstr string) {
.........
}
And
Func (Session *mysession) process (Xmlstr string) {
.........
}
The difference
*mysession represents the mysession of the reference address, and mysession is a struct, if the thinking of Java is to think that the complex data type should be a reference pass, within the function of the mysession change is useful
And not in Golang, most of the Golang are value passing including structs, arrays, except slice map channel is a reference pass, for Func (Session mysession) process (Xmlstr string {} is a copy of the mysession, the function inside the functions will not reflect the original mysession, and the Func (session *mysession) process (Xmlstr string) {} can, because * MySession is a reference address, the reference address value passed the copy of the reference address, the role of it is to reflect the original structure, if it is a complex struct, and forget to add *, then the entire structure is copied value is passed, the performance can be imagined very bad, And you're not going to affect the outside structure at all.