go notes (go in the method invocation)

Methods recent contacts go and find java language to call some similar but also has its own point of attention

go pack my understanding is the smallest module is isolated

First created in the src directory main.go file  package for the main , and then create module1 directory under src, creates two files packageStrut.go in module1 directory, packageStrut2.go    package are module1

After you create the following

 

 

 

 

 

 

 

 

Statement 1. Under the same method and a module can not be reused

  E.g. packageStrut.go declare a method and structure

package module1

import "time"

type People struct {
    UserName string
    PassWord string
}
func NowTime() time.Time  {
    return time.Now()
}

  Then packageStrut2.go repeated error statement directly

 

 

 

2. same package and declare the following method can be invoked directly by the method name

  Such as modifying packageStrut2.go method called directly packageStrut in NowTime method, the People above conflict packageStrut2 conflict revised conflict disappear Person, a new instance of Person

 

 

3. Call the different methods and statements in the package method name can only be called the first letter capitalized method

  

  For example in the first packageStrut2 GetNanoTime () method first letter to lowercase, and then call packageStrut of NowTime () getNanoTime the method and packageStrut2 modify () method main.go respectively, will succeed the former, the latter will compile error

 

 

 

 

 

   Class is the same, if the packageStrut2 the Person changed person, then this person is only visible under the same package, the compiler will error

  

 

Guess you like

Origin www.cnblogs.com/hetutu-5238/p/11772784.html
Go