Docker 设置代理

配置代理 # sudo mkdir -p /etc/systemd/system/docker.service.d # 写入 /etc/systemd/system/docker.service.d/proxy.conf [Service] Environment="HTTP_PROXY=http://bb.bb.com" Environment="HTTPS_PROXY=http://bb.bb.com" Environment="NO_PROXY=aa.bb.com" 然后 sudo systemctl daemon-reload sudo systemctl restart docker 配置镜像仓库 # 更新:大部分已经不可用 Azure 中国镜像 https://dockerhub.azk8s.cn 阿里云加速器(需登录账号获取) 网易云加速器 https://hub-mirror.c.163.com 对于使用 systemd 的系统
阅读全文 →

Git 常用撤回操作

Git 常用撤销操作 1 没有 add 撤销 # git checkout <file-path> 这样就可以把文件恢复到 git 版本里的样子。 2 add 后撤销 # 如果修改的文件已经 add 了,可以用下面的方法撤销 add。 git reset HEAD <file-name> # 撤销某个文件 git
阅读全文 →

Go channel 实现

整体结构 # Channel 的操作对应在运行时里的方法(都在 $GORROT/src/runtime/chan.go 里) Channel 操作 运行时方法 make(chan int, 4) makechan(int, 4) make(chan int) makechan(int, 0) ch <- v chansend1(ch, &v) v <- ch chanrecv1(ch, &v) close(ch) closechan(ch) channel 的基本数据结构 # makechan 返回的是一个叫做 hchan 的结构。所以 chan
阅读全文 →

go generate 使用

当运行 go generate 命令时,他会扫描当前包相关的源代码文件,找出所有包含有 //go:generate 的特殊注释,提取并执行注释后面的命令,命令为可执行程序,如同在 shell 下面执行。 需要注意的 这个注释必
阅读全文 →

go module 使用

1 背景 # Go 在 1.11 版本上发布了 go module 版本管理方案,用于解决被人诟病已久的 Go 项目版本管理问题。这个方案最早来自 Go & Versioning。这个方案引入了一些新的概念,也抛
阅读全文 →

go trace 使用

1 Go trace 介绍 # go trace 在 go 1.5 版本加入,会在运行中收集以下事件的所有数据 创建,启动和终止 goroutine 阻塞/非阻塞 goroutines(syscalls, channels, locks) 网络 io Syscalls gc 收集后不会做任何类型的聚合和抽样。 pprof 用来分析 CPU 和内
阅读全文 →

Go 图片处理库

图表渲染 # https://github.com/go-echarts/go-echarts 根据配置渲染出 echarts 的 json 配置,然后输出。感觉本质上还是 echarts 渲染的页面。 这个不提供生成图片。 https://github.com/vdobler/chart star:90 https://github.com/gonum/plot star: 126 https://github.com/wcharczuk/go-chart star: 2439 简单的图表生成 Canvas 转图片 # https://github.com/tfriedel6/canvas star: 238 HTML 转图
阅读全文 →

Go pprof 使用

1 概览 # pprof 是 Go 提供的一套可视化和分析性能分析数据的工具。 主要包含两部分 runtime/pprof 编译进了每个 go 程序 go tool pprof 用来分析 profile Profiling 可以翻译成画像,类似在侦破案件的时候警察会对嫌疑人做
阅读全文 →

Go 中 JSON 的特殊使用技巧

修改序列化后的 Key 值 # type User struct { ID int `json:"id"` Name string `json:"name"` } // output {"id": 12, "name": "laily"} 数字转字符串 # 前端 js 对 int64 的处理可能会因为溢出导致无法准确处理,因此我们期望可以返回字符串类型。 type User struct { ID int64
阅读全文 →

Systemd 使用

非 root 用户使用 Systemd # 需要 root 用户执行下面的命令将用户的服务长驻 sudo loginctl enable-linger <username> 创建服务 # mkdir ~/.config/systemd/user cd ~/.config/systemd/user vim test.service service 文件 [Unit] AssertPathExists=/home/ghost/ghost [Service] WorkingDirectory=/home/ghost/ghost Environment=GHOST_NODE_VERSION_CHECK=false ExecStart=/usr/bin/npm start --production Restart=always PrivateTmp=true NoNewPrivileges=true [Install] WantedBy=default.target 常规操作 # systemctl --user enable test.service systemctl --user start test.service systemctl --user status test.service 查看日志
阅读全文 →