Go Language Learning Tips (i)

Source: Internet
Author: User

The boundary of the defer

Defer is a function-bound, that is, it will only run when the current function is going to exit.


Return of Nested Channel Select


① for nested the same channel select, how to want to return layers, the best way is to directly close the channel

Package Mainimport ("FMT", "Time") Func main () {stopc: = make (chan int) go func () {select {case <-stopc:fmt. Println ("Stopc 0") Select {case <-stopc:fmt. Println ("Stopc 1")}fmt. Println ("Stopc 2")}} ()//Stopc <-2//stopc <-2close (STOPC) time. Sleep (time. Second * 5)}

Also See:go Sandbox


Fork the correct posture of the other project


For example, there is a project "Http://github.com/sirupsen/logrus", you see he is a little uncomfortable want to pity dorado things. So fork a new project "Http://github.com/auxten/logrus", but the code will have a lot of "import" Http://github.com/sirupsen/logrus/xxx ""


You go directly to modify the code project will still refer to the original, pull request the original author can not be passed quickly, urgent, how to do?


①go get someone else code, here is

Go get Github.com/sirupsen/logrus

② add a new remote to your project directly, pointing to your own repo, command:

git remote add auxten [email protected]:auxten/logrus.git

③ Create a new branch, called the Aux Bar, and let the branch point to this remote. Command:

git checkout-b aux && git branch-u auxten/master aux

④ the final. Git/config probably looks like this:

[core]    repositoryformatversion = 0      filemode = true    bare = false     logallrefupdates = true    ignorecase = true     precomposeunicode = true[remote  "origin"]    url =  https://github.com/sirupsen/logrus        fetch = + refs/heads/*:refs/remotes/origin/*[remote  "Auxten"]    url = [email  protected]:auxten/logrus.git        fetch = +refs/heads/*: refs/remotes/auxten/*[branch  "aux"]    remote = auxten         merge = refs/heads/master[push]    default =  upstream 

⑤push code is used

git push-u auxten aux:master


This command means: Push and set the upstream of Aux to Auxten master.


The method is not perfect, but at least it is more elegant to solve the problem of local development compilation.


This article originates from: 1190000006913499


    --- November 26 (Saturday) class opened

http://www.51reboot.com/course/actual/

QQ Registration: 979950755

This article is from the "Reboot DevOps Development" blog, please be sure to keep this source http://opsdev.blog.51cto.com/2180875/1884242

Go Language Learning Tips (i)

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.