​​​​ go命令行工具 | 苏生不惑的博客

go命令行工具

安装go

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
yum install -y go
[root@VM_0_14_centos shadowsocks]# go version
go version go1.9.4 linux/amd64
[root@VM_0_14_centos shadowsocks]# go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/go"
GORACE=""
GOROOT="/usr/lib/golang"
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build058581188=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

百度网盘客户端

1
2
3
4
5
6
7
8
9
10
go get -u https://github.com/iikira/BaiduPCS-Go
BaiduPCS-Go update
# 搜索根目录的文件
BaiduPCS-Go search -path=/ 关键字

# 搜索当前工作目录的文件
BaiduPCS-Go search 关键字

# 递归搜索当前工作目录的文件
BaiduPCS-Go search -r 关键字

简单图床 AUXPI

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
cd $GOPATH/src
git clone git@github.com:aimerforreimu/AUXPI.git
cd AUXPI/
go get -u github.com/beego/bee
$ bee run auxpi
______
| ___ \
| |_/ / ___ ___
| ___ \ / _ \ / _ \
| |_/ /| __/| __/
\____/ \___| \___| v1.10.0
2018/11/08 19:53:08 INFO ▶ 0001 Using 'auxpi' as 'appname'
2018/11/08 19:53:08 INFO ▶ 0002 Initializing watcher...
auxpi/routers
auxpi
2018/11/08 19:53:25 SUCCESS ▶ 0003 Built Successfully!
2018/11/08 19:53:25 INFO ▶ 0004 Restarting 'auxpi.exe'...
2018/11/08 19:53:25 SUCCESS ▶ 0005 './auxpi.exe' is running...
2018/11/08 19:53:25.404 [I] [parser.go:96] generate router from comments
2018/11/08 19:53:25.407 [I] [parser.go:96] generate router from comments
2018/11/08 19:53:25.460 [I] [asm_amd64.s:1333] http server Running on http://:2333

基于终端的图形活动监视器

1
2
3
4
5
6
git clone --depth 1 https://github.com/cjbassi/gotop /tmp/gotop
sh /tmp/gotop/scripts/download.sh
mv gotop /usr/local/bin
go get github.com/cjbassi/gotop
# 直接执行
gotop

下载视频

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
go get -u github.com/iawia002/annie
$ annie -i https://www.bilibili.com/video/av21877586 https://www.bilibili.com/video/av21990740

Site: 哔哩哔哩 bilibili.com
Title: 【莓机会了】甜到虐哭的13集单集MAD「我现在什么都不想干,更不想看14集」
Type: video
Streams: # All available quality
[default] -------------------
Quality: 高清 1080P
Size: 51.88 MiB (54403767 Bytes)
# download with: annie -f default "URL"


Site: 哔哩哔哩 bilibili.com
Title: 【莓救了】甜到虐哭!!!国家队单集MAD-当熟悉的bgm响起,眼泪从脸颊滑下
Type: video
Streams: # All available quality
[default] -------------------
Quality: 高清 1080P
Size: 77.63 MiB (81404093 Bytes)
# download with: annie -f default "URL"

跨平台的网络性能测量工具

1
2
3
4
5
6
7
go get github.com/Microsoft/ethr
[root@VM_0_14_centos ~]# /root/go/bin/ethr -s
Listening on 9991 for control plane
Listening on 9996 for TCP latency tests
Listening on 9998 for TCP conn/s tests
Listening on 9999 for TCP bandwidth tests
Unable to start HTTP server, so HTTP tests cannot be run: listen tcp :8080: bind: address already in use

海报生成器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
git clone https://github.com/qbhy/poster-generater.git
cd poster-generater
go build

[root@VM_0_14_centos poster-generater]# ./poster-generater 7877
[GIN-debug] [WARNING] Now Gin requires Go 1.6 or later and Go 1.7 will be required soon.

[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
- using env: export GIN_MODE=release
- using code: gin.SetMode(gin.ReleaseMode)

[GIN-debug] GET /assets/*filepath --> poster-generater/vendor/github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1 (3 handlers)
[GIN-debug] HEAD /assets/*filepath --> poster-generater/vendor/github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1 (3 handlers)
[GIN-debug] POST /poster --> main.main.func1 (3 handlers)
[GIN-debug] Listening and serving HTTP on :7877
[GIN] 2018/12/19 - 11:48:03 | 404 | 1.05µs | 218.30.113.34 | GET /

HTTP(S)代理, 用于抓包调试

1
2
3
4
5
6
docker run --name mars -p 8888:8888 -p 9999:9999 -d ouqg/mars:1.0.0
wget https://github.com/ouqiang/mars/releases
解压压缩包
启动: ./mars server
访问代理: http://localhost:8888
查看流量web页: http://localhost:9999, 客户端可扫描二维码下载根证书

自助 Git 服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
sudo su - git
cd ~
# create a folder to install 'go'
mkdir local
# Download go (change go$VERSION.$OS-$ARCH.tar.gz to the latest release)
wget https://storage.googleapis.com/golang/go$VERSION.$OS-$ARCH.tar.gz
# expand it to ~/local
tar -C /home/git/local -xzf go$VERSION.$OS-$ARCH.tar.gz
sudo su - git
cd ~
echo 'export GOROOT=$HOME/local/go' >> $HOME/.bashrc
echo 'export GOPATH=$HOME/go' >> $HOME/.bashrc
echo 'export PATH=$PATH:$GOROOT/bin:$GOPATH/bin' >> $HOME/.bashrc
source $HOME/.bashrc
# 下载并安装依赖
$ go get -u github.com/gogs/gogs

# 构建主程序
$ cd $GOPATH/src/github.com/gogs/gogs
$ go build

cd $GOPATH/src/github.com/gogs/gogs
./gogs web -port 3001 &

2019/01/23 14:16:48 [ WARN] Custom config '/root/go/src/github.com/gogs/gogs/custom/conf/app.ini' not found, igng first time
2019/01/23 14:16:48 [TRACE] Custom path: /root/go/src/github.com/gogs/gogs/custom
2019/01/23 14:16:48 [TRACE] Log path: /root/go/src/github.com/gogs/gogs/log
2019/01/23 14:16:48 [TRACE] Log Mode: Console (Trace)
2019/01/23 14:16:48 [ INFO] Gogs 0.11.85.1225
2019/01/23 14:16:48 [ INFO] Cache Service Enabled
2019/01/23 14:16:48 [ INFO] Session Service Enabled
2019/01/23 14:16:48 [ INFO] Run Mode: Development
2019/01/23 14:16:50 [ INFO] Listen: http://0.0.0.0:3000
2019/01/23 14:16:50 [FATAL] [...rfave/cli/command.go:193 Run()] Failed to start server: listen tcp 0.0.0.0:3000: use
[root@VM_0_14_centos gogs]# lsof -i:3000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
docker-pr 3588 root 4u IPv6 29572 0t0 TCP *:hbci (LISTEN)

修改端口 参考 https://gogs.io/docs/advanced/configuration_cheat_sheet.html
touch custom/conf/app.ini
vi app.ini
[server]

HTTP_PORT = 6666

nginx 反向代理
server {
listen 80;
server_name git.crystalnetwork.us;

location / {
proxy_pass http://localhost:3001;
}
}

访问
http://118.24.158.116:3001/ 如果无法访问,可能是项目在root目录下的原因,重新设置gopath,重新go get和build

λ shs root@118.24.158.116
PTY allocation request failed on channel 0
Hi there, You've successfully authenticated, but Gogs does not provide shell access.
If this is unexpected, please log in with password and setup Gogs under another user.
Connection to 118.24.158.116 closed.
Mac平台下,进入~/.ssh目录,之前肯定有了一对密钥,公钥id_rsa.pub和私钥id_rsa。
使用命令生成新的一对密钥,切记要命名跟原来的密钥不同,ssh-keygen -t rsa -f gogs_id_rsa -C "xiong-wei@hotmail.com"
在.ssh目录中创建config文件,然后添加如下内容:
Host 118.24.158.116
IdentityFile ~/.ssh/gogs_id_rsa
IdentitiesOnly yes

切换 Git 分支

1
2
3
4
5
6
7
8
9
10
go get -u github.com/royeo/git-checkout-branch
如果你正在使用 GO1.11 Module,使用以下命令进行安装:

GO111MODULE=off go get -u github.com/royeo/git-checkout-branch
建议为 checkout-branch 设置别名,例如 cb,这样就可以直接使用 git cb 来进行分支切换。

git config --global alias.cb checkout-branch
帮助

使用 git checkout-branch help 获取帮助信息。

命令行压缩和解压

1
2
3
4
5
6
7
8
9
10
11
12
go get -u github.com/mholt/archiver/cmd/arc
$ arc archive test.tar.gz file1.txt images/file2.jpg folder/subfolder
$ arc unarchive test.tar.gz

$ arc ls caddy_dist.tar.gz
drwxr-xr-x matt staff 0 2018-09-19 15:47:18 -0600 MDT dist/
-rw-r--r-- matt staff 6148 2017-08-07 18:34:22 -0600 MDT dist/.DS_Store
-rw-r--r-- matt staff 22481 2018-09-19 15:47:18 -0600 MDT dist/CHANGES.txt
-rw-r--r-- matt staff 17189 2018-09-19 15:47:18 -0600 MDT dist/EULA.txt
-rw-r--r-- matt staff 25261 2016-03-07 16:32:00 -0700 MST dist/LICENSES.txt
-rw-r--r-- matt staff 1017 2018-09-19 15:47:18 -0600 MDT dist/README.txt
-rw-r--r-- matt staff 288 2016-03-21 11:52:38 -0600 MDT dist/gitcookie.sh.enc

生成可执行文件

1
2
3
4
5
6
7
8
9
10
11
12
13
go get github.com/mitchellh/gox
λ gox -h
Usage: gox [options] [packages]

Gox cross-compiles Go applications in parallel.

If no specific operating systems or architectures are specified, Gox
will build for all pairs supported by your version of Go
git clone https://github.com/hezhizheng/go-movies
[root@VM_0_11_centos go-movies]# gox -osarch="linux/amd64"
Number of parallel builds: 1

--> linux/amd64: go_movies

Golang 新手教程:入门速成指南

go 语言优秀开源项目汇总

使用 go 的 gin 和 gorm 框架来构建 RESTful API 微服务

Golang 实现 PHP 常用内置函数

golang学习笔记

使用 Gogs 搭建自己的 Git 服务器

Go开源项目学习

go编码规范

自动生成Restful API文档

http代理工具

【Go学习笔记】2018-12-27

ss代理

一款极易搭建的自助 Git 服务

go教程

内网穿透的高性能的反向代理应用

监控报警系统

初学者的 Go 语言教程

一个简单高性能的 router

Go 语言数据结构代码生成器

go-by-example

go学习

去中心化数字资产闪兑平台

《 刻意学习 Golang 》

《Go语言四十二章经》

搭建并行处理管道,感受GO语言魅力

A global proxy for go modules

The Central Go Modules Repository

程序员内功系列–常用命令行工具