Go Language Project Management

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Go is a programming language that comes with project management and is easy to use.

Directory structure

Typically, a Go language project (assuming the root directory of this project is Goprojectroot) is this:

First Level Directory

 GoProjectRoot/src    #包含项目的源代码文件; GoProjectRoot/pkg    #包含编译后生成的包/库文件; GoProjectRoot/bin    #包含编译后生成的可执行文件。

Where the SRC directory requires our own creation, the remaining two directories are automatically produced at the time of execution go install .

Second Level directory

In the SRC directory below, is our project all the source code, generally according to different modules to be placed separately:

<Goprojectroot>|--<src>|--<Module1>|--Mudule1.Go          |--<Module2>|--Module2.Go          |--<Main>|--Main.Go

Compile execution

Gopath & Goroot

differs fromMakefileOrCmake, we can execute our own in any path.Go Installcommand, this requires the go compiler to know where to look for the required packages. This process relies on the GOPATH And g o r o o t Even a variable.
Go first from g o r o o t If you don't find it, you can find the package from GOPATH The results are not found and we can use theGo envOutput the environment variable settings for go.

Go run

Meaning

Execute this go file. It sounds like executing a script, using it almost as well as executing a script.
But 、、、 go language is compiled language!!!
This command must be to compile the production temporary execution file, execute the temporary execution file, delete the temporary execution file.

Command format:

Go Run Xxx.go

Role:

    • Perform this xxx.go , print out.

Go Build

Meaning

Compile this go file.

Command format:

Go build xxx.go
Go build -o nameyouneed xxx.go

Role

In the current directory production execution file, if there is no-o parameter, the executable file will have the same name as the . Go suffix.

Go Install

Meaning

Compile production to install the entire module.

Command format

go install xxx
Note: XXX is the name of our module.
# # # Effect

    • If the packet of this module is main, then the production executable file. Placed under the first-level directory bin, the name is the same as the module name.
    • If this module is not the main module, compile the production xxx.a file. Placed under the first-level directory PKT.
    • All modules dependent on this project module will be compiled into the corresponding . a file. Placed under the first-level directory PKT.

Advantage:

Go install can be executed on any path.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

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.