Go with Golang

一些知识点

  • 静态类型但有类动态的特性
  • 相比Java:打包和运行方式不同,Go编译打包为二进制依赖操作系统不需要运行时环境,性能上相比JIT基于目前的测试没有优劣
Paste_Image.png

􏰀 Goroutines—A goroutine is a function that runs independently of the functionthat started it. Sometimes Go developers explain a goroutine as a function thatruns as if it were on its own thread.
􏰀 Channels—A channel is a pipeline for sending and receiving data. Think of it asa socket that runs inside your program. Channels provide a way for one gorou-tine to send structured data to another.

Here are some of the advantages of Goroutines over threads:
You can run more goroutines on a typical system than you can threads.
Goroutines have growable segmented stacks.
Goroutines have a faster startup time than threads.
Goroutines come with built-in primitives to communicate safely between themselves (channels).
Goroutines allow you to avoid having to resort to mutex locking when sharing data structures.
Goroutines are multiplexed onto a small number of OS threads, rather than a 1:1 mapping.
You can write massively concurrent servers withouth having to resort to evented programming.

  • WaitGroup和Lock
  • defer和GC
  • *和&
  • package/import/func
  • variable和assignment
  • error和panic

An error indicates that a particular task couldn’tbe completed successfully.
A panic indicates that a severe event occurred, probablyas a result of a programmer error.

Tips

.zshrc
export GOPATH=$HOME/golang
export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin
  • 网络原因导致go get不工作:
下载tools的github repo:https://github.com/golang/tools
改目录为golang.org/x/tools,并copy到/usr/local/Cellar/go/1.6.3/libexec/src
运行go install golang.org/x/tools/cmd/goimports
成功的话能找到GOPATH/bin/goimports
  • 如何下载包?例如:go get github.com/kylelemons/go-gypsy/yaml,在GOPATH/src下面能发现下载好的package

  • Intellij里面可以增加Go插件的Global libraries路径$GOPATH

References

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Many project websites link to this document in their sect...
    Justin_Zhai阅读 8,275评论 2 4
  • 今天我要跟大家介绍一下我的学校一威海巿码头小学。它环境优美,花草树木,构成了美丽的校园。 早上阳光明媚我走进了校园...
    菠萝一一菠萝蜜阅读 3,709评论 0 0
  • 珠江冷 迷人的蓝是热情的女人美丽的肉体珠江水摇曳火热的舞大妈们锲而不舍的心恋人相拥在冷风吹起的夜小女孩欢快地玩着小...
    南溪向南北歌流海阅读 1,553评论 0 0
  • 终于轮到我们开始讨论去大城市还是待在老家工作的问题,曾经我以为这个话题离我们很远,没想到现在打开朋友圈都在讨论这个...
    90后职场说阅读 3,449评论 0 0