Go language Commentary goroot, Gopath, GOBIN

Source: Internet
Author: User

Go is a brand new static type development language, with,,,,, 自动垃圾回收 丰富的内置类型 函数多返回值 错误处理 匿名函数 并发编程 , 反射 etc. features.

goThe command relies on an important environment variable: $GOPATH
GOPATHAllow multiple directories, when there are multiple directories, note the delimiter, multiple directories when Windows is a semicolon;

When there are multiple GOPATH时 default go get packages to be acquired in the first directory

$GOPATHTable of Contents conventions have three subdirectories
    • srcStore source code (e.g.. Go. C. H. S, etc.) according to Golang default conventions, the current working path of the commands such as Go Run,go install (i.e. execute the above command on this path).
    • pkgIntermediate files generated at compile time (for example:. A) Golang when compiling a package
    • binCompiled executable (for convenience, this directory can be added to the $PATH variable, if there are multiple gopath, then use to ${GOPATH//://bin:}/bin Add all the bin directory)
Code Catalog Structure Planning

Gopath under the SRC directory is the main directory of the next development program, all the source code is placed under this directory, then generally we practice is a directory of a project,

For example: $GOPATH/src/mymath represents mymath this application package or executable application, depending on whether the packages are main or otherwise, the main word is the executable application, and the other is the application package, which will be introduced in detail in the future.

First look at my go environment: Go env
C:\users\administrator>Go envSetGoarch=AMD64Setgobin=SetGoexe=. EXESetGohostarch=AMD64Setgohostos=WindowsSetgoos=WindowsSetGopath=D:\projectSetGorace=Setgoroot=D:\BaiduNetdiskDownload\goSetGotooldir=D:\BaiduNetdiskDownload\go\pkg\tool\windows_amd64Setgccgo=GccgoSetCc=GCCSetGogccflags=-m64-mthreads-fmessage-length=0Setcxx=g++SetCgo_enabled=1SetCgo_cflags=-g-O2Setcgo_cppflags=SetCgo_cxxflags=-g-O2SetCgo_fflags=-g-O2SetCgo_ldflags=-g-O2SetPkg_config=pkg-config
Goroot

is actually the Golang installation path.
When you've installed the Golang, you actually have it.

GOBIN

First look at the structure:

We usually do a go build under the project directory, for example:

D:\project\src\go_dev\day1\package_example\main>Go run main.go

Now need to compile Main.go,golang will automatically go to src under the Hello directory, because my main.go code in the Open import Packag main package, so can be compiled into an executable file, but so the default in the current directory to generate executable files, although you can specify the directory , but it is not very convenient to feel

D:\project>go Build Go_dev/day1/package_example\main

So there are two very useful commands: Go get and go install

Go get

Go get will do two things:
1. Download the required package from the remote
2. Execute Go Install

Go Install

Go install will generate executable files directly into the bin directory, of course, this is a prerequisite
You compile the executable file, if it is a normal package, it will be compiled into the PKG directory, the file is. A end

A complete development Directory of Go
Go_project//go_project for Gopath directory--bin--MyApp1//Compile Build--MYAPP2//Compile Build--MYAPP3//Compile Build--Pkg--src--MyApp1//Project1--Models--Controllers--others--Main.go--MYAPP2//Project2--Models--Controllers--others--Main.go--MYAPP3//Project3--Models--Controllers--others--Main.go

Reference article Address:

https://studygolang.com/articles/7202

Http://www.cnblogs.com/zhaof/p/7906722.html

Go Language Tutorials goroot, Gopath, GOBIN

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.