Catalog:玩转编程语言 - Golang 专题

摘要

  • ABC
  • 基于 Golang 的应用
  • Golang 最佳实践

围棋十诀

一、不得贪胜。
二、入界宜缓。
三、攻彼顾我。
四、弃子争先。
五、舍小就大。
六、逢危须弃。
七、慎勿轻速。
八、动须相应。
九、彼强自保。
十、势孤取和。
————(唐)王积薪

一、ABC

1.1 Install

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
tar -C /usr/local/go-$version -xvf go-$version.tar.gz

cd /usr/local/go-$version/src
./all_bash

#compile,build and test

unset GOROOT
unset GOPATH
unset GOAPPATH

export GOROOT=/usr/local/go
export GOPATH=$GOROOT/bin
export GOAPPATH=$GOROOT/bin/bin
export PATH=$PATH:$GOPATH:$GOAPPATH

1.2 Go Version Manage

1
2
3
4
5
//atom 代码提示
go get -u github.com/jstemmer/gotags
//源代码目录执行
gotags -tag-relative=true -R=true -sort=true -f="tags" -fields=+l .

  • build
1
2
3
4
5
6
7
8
9
10
11
12
13
14

## 交叉编译

build-linux:
export CGO_ENABLED=0 && export GOOS=linux && export GOARCH=amd64 && go build
build-wins:
export CGO_ENABLED=0 && export GOOS=windows && export GOARCH=amd64 && go build
build-solaris:
export CGO_ENABLED=0 && export GOOS=solaris && export GOARCH=amd64 && go build

## Go supports Solaris 11 on amd64, but not sparc.To build for sparc you need to use gccgo.

## 压缩
go build -ldflags '-w -s'

二、基于 Golang 的应用

2.1 基于Go语言构建RESTful JSON API

2.2 基于Kafka构建事件溯源模式的微服务

讨论如何借助Kafka实现分布式消息管理,使用事件溯源(Event Sourcing)模式实现原子化数据处理,使用CQRS模式(Command-Query Responsibility Segregation )实现查询职责分离,使用消费者群组解决单点故障问题,理解分布式协调框架Zookeeper的运行机制。整个应用的代码实现使用Go语言描述。

2.3 开源技术架构漫谈:应用程序开发中的日志管理

2.4 网络数据包的捕获、过滤和分析(Packet Capturing)

  • What is Packet Capturing
  • How can it be used
  • What is libpcap
  • What is tcpdump & winpcap & snoop
  • What is BPF
  • What is gopacket

2.5 数据可视化(五)基于网络爬虫制作可视化图表

  • 基于网络爬虫的可视化图表:golang,goquery
  • 案例:最近十年全国彩票销售变化情况
  • 案例:中国科学院院士分布
  • 数据可视化技术方案:基于 SVG (D3、Raphael)、基于 Canvas(Echarts)

三、Golang 最佳实践

3.1 Grammar Tips & Simple Demo

The interface is a tool so that you can wire dependencies just by their behaviour, not by how they implement that behaviour.

3.2 Specialist: Architecture

3.3 Go Repository

goproxy

golang实现的高性能http,https,websocket,tcp,udp,socks5代理服务器,支持正向代理、反向代理、透明代理、内网穿透、TCP/UDP端口映射、SSH中转,TLS加密传输,协议转换

3.3 Business Product List

Books

《Introducing Go: Build Reliable, Scalable Programs》

《The Go Programming Language》

《Go Web Programming》

Concurrency in Go: Tools and Techniques for Developers

《Go Programming Blueprints》

  • 特点:covers a lot of topics,such as web services,command-line tools,microservices and app deployment.
  • 预览链接

Others

book: https://github.com/thewhitetulip/web-dev-golang-anti-textbook/
youtube series: https://www.youtube.com/playlist?list=PL41psiCma00wgiTKkAZwJiwtLTdcyEyc4
code: http://github.com/thewhitetulip/Tasks

Quickstart

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//通过channel 实现协程间通信
// https://golangcaff.com/docs/the-way-to-go/142-covariance-channel/130
import (
"fmt"
"time"
)
func worker(done chan bool) {
time.Sleep(time.Second)
// 通知任务已完成
done <- true
}
func main() {
done := make(chan bool, 1)
go worker(done)
// 等待任务完成
<-done
}

Tips

Security Resources

扩展阅读

参考文献

欢迎扫码关注微信公众号获取最新动态,读者交流 QQ 群:338272982 。

推荐文章