Go Language Learning Tips (i)

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

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, the best way to get layers back is to close the channel directly
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 <- 2    close(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 upset want to pity dorado things. So fork a new project "Http://github.com/auxten/logrus ...", but there will be a lot of "import" http://github.com/sirupsen/logrus/xxx in the code ... ""

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?

    1. Go get someone else code, here is

      go get github.com/sirupsen/logrus
    2. Add a new remote to the project directly, pointing to your own repo, command:

      git remote add auxten git@github.com:auxten/logrus.git
    3. 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
    4. The final. Git/config is likely to look like this:

      [core]repositoryformatversion = 0 filemode = truebare = falselogallrefupdates = trueignorecase = trueprecomposeunicode = true[remote "origin"]url = https://github.com/sirupsen/logrusfetch = +refs/heads/*:refs/remotes/origin/*[remote "auxten"]url = git@github.com:auxten/logrus.gitfetch = +refs/heads/*:refs/remotes/auxten/*[branch "aux"]remote = auxtenmerge = refs/heads/master[push]default = upstream
    5. The 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 it can at least gracefully solve the problem of local development and compilation.

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.