Check out the remaining 7 practical tips and more important content here
Brief introduction: Go language actual combat learning tips
Using a single GOPATH Multiple GOPATH situations are not elastic. GOPATH itself is highly self-contained (via the import path). Having more than one GOPATH can cause some side effects, such as the possibility of using different versions of a given library. You might upgrade it in one place, but not in another. Also, I haven’t come across a situation where I need to use more than one GOPATH. So using a single GOPATH will improve your Go development.
A lot of people disagree with this, so I’ll make a few clarifications. Large projects like ETCD or CamListore use tools like Godep to save all dependencies in a directory. That is, the projects themselves have a single GOPATH. They can only find the corresponding version in this directory. Unless your project is large and extremely important, don’t use a different GOPATH for each project. If you think your project needs its own GOPATH directory, create it, otherwise don’t try to use multiple GOPATH. It just slows you down.
Encapsulate for-select in a function and if you want to get out of for-select under certain conditions, you use tags. Such as:
func main() {
L:
for {
select {
case< - time. After (time. Second) : FMT. Println (" hello ") the default:breakL}} FMT.Println(" ending ")Copy the code
As you can see, you need to combine the break to use the tag. It serves a purpose, but I don’t like it. The for loops in this example may seem small, but they are usually larger, and the conditions for judging a break are more verbose.
If I need to exit the loop, I’ll wrap for-select in a function:
func main() {foo() ftt.println (" ending ")} funcfoo() {
for {
select {
case< - time. After (time. Second) : FMT. Println (" hello ") the default:return}}} you can also return an error (or any other value), which is equally nice, just by: // blockiferr := foo(); err ! = nil {// process err}Copy the code
Use the tagged syntax when initializing a structure
Keywords: JavaScript security database connection testing technology Go database Windows
Keywords: Nail scan code into the group, Ali cloud and other leaders from all walks of life waiting for you oh ~