This is a creation in Article, where the information may have evolved or changed.
Overall structure
First of all we need to know that the project structure is often referred to as gopath
. Similar to the classpath in our java. Gopath contains three pieces of content:,,, what are src
bin
package
they used for?
- SRC Store is our source code, that is, we write the Go language program
- The bin holds the compiled executable file
- The package stores the files that are generated after compilation
Structure under SRC
SRC We can create multiple projects
--src --app1 --a --b --c --main.go --app2 --main.go --app3....
Instance
Create a,b,c,d four folders separately under SRC
Where a folder is created under Folder A1,a2
Create the A_sub folder under A1 and create Suba.go
package a_subimport ("fmt")func SubAMethod() {fmt.Println("a_sub/SubAMethod")}
A1.go and A2.go are created under A1 and A2 respectively
package a1import ("a/a1/a_sub""fmt")func PrintA1() { fmt.Println("a/a1")}package a2import "fmt"func PrintA2() { fmt.Println("a/a2")}
Create B1.go and B2.go under the B folder
package bimport "fmt"func printB1() { fmt.Println("b.b1")}package bimport "fmt"func PrintB() { printB1() fmt.Println("b.b2")}
Create c.go under the C folder
package mainimport ( "a/a1" "a/a2" "b")func main() { a1.PrintA1() a2.PrintA2() b.PrintB()}
Create d.go under the D folder
package mainimport ( "fmt")func main() { fmt.Println("Hello world")}
The final file directory structure is as follows
Multiple Gopath directories
In addition, we can configure multiple Gopath directories to create their own projects under SRC under each Gopath directory, so that so many items are not coupled together. Multiple Gopath directories are used, (Windows) or: (Linux) separated.
Reference: http://www.cnblogs.com/auh2010006/p/6343231.html