Golang Tour-project structure. MD

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.