This is a creation in Article, where the information may have evolved or changed.
As shown below, the Main.go file functions if you want to invoke the specific implementation of the test () function in Func1.go in the Func folder in the Main.go sibling directory.
test |--func |--func1.go |--func2.go |--main.go
What you need to write in the Main.go file is
package mainimport( "test/func")func main(){ func.Test()}
One of the things to note is:
1, test project to Golang in the $gopath path.
For example $GOPATH=/home/data
, the test file path is /homg/data/src/test
then the path of the import reference in Main.go "test/func"
. If the file path is /home/data/src/XXX/test
so main.go, the path to the import reference is "XXX/test/func"
. The external file referenced in import is visible according to the relative path of the $gopath.
$GOPATH
There will be three directories generated under the path src
, pkg
and bin
. src
store source code (e.g., .go
.c
.h
.s
etc.), pkg
intermediate files generated at compile time (e.g.: .a
), bin
executable files generated after compilation (for convenience, this directory can be added to the $PATH
variable, If there are multiple GOPATH
, then use ${GOPATH//://bin:}/bin
the Add all Bin directory).
2, the called Func1.go file in the test () function, the first letter to uppercase.
Golang the first letter of the variable, method name is uppercase when the default can be called externally, the first letter is lowercase when the default cannot be called externally.