1 Download Dependency Package issues
Cannot find package "GITHUB.COM/GOCQL/GOCQL" in any of:
/USR/LOCAL/SRC/GO/SRC/GITHUB.COM/GOCQL/GOCQL (from $GOROOT)
($GOPATH not set)
The solution method;
1. Set Goroot, Gopath
Gopath is used to download dependent packages for third parties.
Go build looks for dependent packages from Goroot and Gopath
Such as:
Export Goroot=/usr/local/src/go
Export path= $PATH: $GOROOT/bin
Export Gopath=/users/test/gopath/go_workspace
2 Download Dependency Packages
Go get GITHUB.COM/GOCQL/GOCQL
2 idea
2.1 IntelliJ Idea 14 using the Go plugin
http://blog.csdn.net/zhouzme/article/details/44133507
3 bytes differs from character
The Golang is stored using UTF-8 encoding. A Chinese can be stored in 3 bytes or 4 bytes. If a character representation is used, it is represented by Rune. []byte represents a byte array, []rune represents an array of characters.]
4 dependency packages for downloading projects with agents
http_proxy=hx.gy:1080 Go get-d-v google.golang.org/grpc
Domain name supported by the HX,GY agent
Android.com
bitbucket.org
Bintray.com
chromium.org
clojars.org
Registry.cordova.io
dartlang.org
download.eclipse.org
Github.com
Githubusercontent.com
golang.org
Googlesource.com
Storage.googleapis.com
Code.google.com
Dl.google.com
Dl-ssl.google.com
getcomposer.org
gradle.org
Gopkg.in
Ionicframework.com
Plugins.jetbrains.com
macports.org
maven.org
melpa.org
Mendeley.com
www.nuget.org
Npmjs.com
npmjs.org
pypi.python.org
packagist.org
Packagecontrol.io
rubygems.org
Repo.typesafe.com
5 gopm instead of Go download third-party dependency packages
Using go get in the country sometimes does not download a dependency package for some websites such as golang.org.
Can be downloaded from golang.org some mirror sites using GOPM.
1) Install GOPM
Go get-u github.com/gpmgo/gopm
The user who executes the command needs to set the Gopath parameter
2) GOPM Get if you do not carry the-G adoption, you will download the dependency package under the vendor directory.
Using the-g parameter, you can download the dependency package to the Gopath directory
GOPM get-g golang.org/x/net
5 Defer execution Process
The defer is executed before the return. This is clearly stated in the official documentation. To use defer without stepping on the pit, the most important thing is to understand that return XXX This statement is not an atomic directive!
The procedure for returning a function is to assign a value to the return value first, then call the defer expression, and finally return to the calling function
6 Package Initialization Sequence
If package P imports packet Q, the INIT function of packet q executes before any function of package p is run.
That is, the function Main.main () will run after all the init () functions have ended
7 Channel
Divided into buffer channel and unbuffered channel, for the Unbuffered channel, the channel acceptance occurs before the transmission of the channel is completed.
That is, when the go process sends information, it is blocked until other threads have accepted the information.
8 Scheduling of Go run-time threads
When a physical thread is blocked due to a process block, the go runtime allocates other threads to execute on the other physical thread.
9 method passing values and passing pointers
Pass a value, which is a copy of an object (individual property values), and the method does not change the property value of the argument.
Passing pointers, methods can change the property values of an argument.
Ten Goroutine
In the same native thread, if the current goroutine does not block, it does not yield the CPU to be executed by the other gorountine of the thread.
If Goroutine is blocked, go automatically assigns other goroutine that are on the same thread as the goroutine to other threads to execute.
Golang values, references, and pointers
Both the original type and the custom type are values passed as arguments to the function. Therefore, when a custom type is passed as a parameter to a function, the value of the actual parameter does not change.
(Java custom objects are reference types).
Golang map, array, channel is a reference type.
Engineering structure of Golang
Project name
--Package 1
---1.go
--Package 2
--2.go
Main.go
Introduction of the package in this project, using the relative path method
such as import "project name/package name" in the original file, if a variable or method does not belong to a class, it belongs to the package. When you import the package, you can use this method
The project needs to be under the $GOPATH/SRC directory (the first directory recommended for Gopath)
The Golang Code organization unit is the package
A package consists of its exported type and function components (Java in class, Java Import can also be specific to the class)
The Golang package import can only be used to package, referencing the types or functions that are everywhere in the package.
Difference between Goroot and Gopath
Goroot is the Go installation directory,
Gopath Download third-party dependency packages and local development projects
Http://www.jianshu.com/p/4e699ff478a5
Go installation and Common commands
Https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/01.1.md
Go get
Use the command go get to download a single package or use ... Download each package in the entire subdirectory